问题描述
我终于将我想要的 3 个地块强制合并为一个包含 3 个子地块的地块……现在我需要添加一个通用的颜色条,最好是水平方向的.此外,现在我将它们作为子图,我已经丢失了上一次迭代中存在的标签.
似乎这些示例表明我 位于轴文档中.
您链接到的示例使用图形的 add_axes
方法作为 add_subplot
的替代方法.图形文档 解释了 add_axes 中的数字是什么:在 rect [left, 底部, 宽度, 高度] 其中所有数量都是图形宽度和高度的分数."
rect = l,b,w,hfig.add_axes(rect)
I finally forced the 3 plots I want into one plot with 3 subplots...now I need to add a common colorbar, preferably horizontally oriented. Also, now that I have them as subplots, I have lost the labels that were there in a previous iteration.
It seems that the examples suggest I add an axes, but I don't quite get what the numbers in the arguments are.
def plot_that_2(x_vals, y_vals, z_1_vals, z_2_vals, z_3_vals, figname, units, efficiency_or_not):
global letter_pic_width
plt.close() #I moved this up from the end of the file because it solved my QTagg problem
UI = [uniformity_calc(z_1_vals), uniformity_calc(z_2_vals), uniformity_calc(z_3_vals)]
ranges = [ str(int(np.max(z_1_vals) - np.min(z_1_vals))), str(int(np.max(z_2_vals) - np.min(z_2_vals))), str(int(np.max(z_3_vals) - np.min(z_3_vals)))]
z_vals = [z_1_vals, z_2_vals, z_3_vals]
fig = plt.figure(figsize = (letter_pic_width, letter_pic_width/3 ))
ax0 = fig.add_subplot(1,3,1, aspect = 1)
ax1 = fig.add_subplot(1,3,2, aspect = 1)
ax2 = fig.add_subplot(1,3,3, aspect = 1)
axenames = [ax0, ax1, ax2]
for z_val, unif, rangenum, ax in zip(z_vals, UI, ranges, axenames):
ax.scatter(x_vals, y_vals, c = z_val, s = 100, cmap = 'rainbow')
if efficiency_or_not:
ax.vmin = 0
ax.vmax = 1
ax.xlabel = 'Uniformity: ' + unif
else:
ax.xlabel = 'Uniformity: ' + unif + ' ' + rangenum + ' ppm'
plt.savefig('./'+ figname + '.jpg', dpi = 100)
To set the xlabel, use ax.set_xlabel('Uniformity: ' + unif)
See more information here in the documentation for axes.
The example you linked to uses the add_axes
method of a figure as an alternative to add_subplot
. The documentation for figures explains what the numbers in add_axes are: "Add an axes at position rect [left, bottom, width, height] where all quantities are in fractions of figure width and height."
rect = l,b,w,h
fig.add_axes(rect)
这篇关于Matplotlib - 2 个问题.常见的颜色条/标签未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!