我正在使用循环创建多幅图像,我想在底部添加水平居中的颜色栏。
我想向图中类似
的图形添加颜色条由以下代码创建:
fig, axes = plt.subplots(nrows = 3, ncols = 2, tight_layout=True)
i = 1
for cut in cuts:
for time in times:
#some code that will get an array for a given cut and time
if cut == 'x':
plt.subplot(3,2,i)
plt.imshow(arr, cmap='gist_heat', aspect='equal', vmin = minimum, vmax = maximum, extent=[np.min(y), np.max(y), np.min(z), np.max(z)], interpolation='spline16', norm=colors.PowerNorm(gamma=1./3.))
plt.title( '..')
plt.xticks(y_ticks)
plt.yticks(z_ticks)
plt.xlabel('${y}$')
plt.ylabel('${z}$')
#plt.colorbar
i += 1
elif cut == 'y':
plt.subplot(3,2,i)
plt.imshow(arr, cmap='gist_heat', aspect='equal', vmin = minimum, vmax = maximum, extent=[np.min(x), np.max(x), np.min(z), np.max(z)], interpolation='spline16', norm=colors.PowerNorm(gamma=1./3.))
plt.title('..')
plt.xticks(x_ticks)
plt.yticks(z_ticks)
plt.xlabel('${x}$')
plt.ylabel('${z}$')
#plt.colorbar
i += 1
elif cut == 'z':
plt.subplot(3,2,i)
I = plt.imshow(arr, cmap='gist_heat', aspect='equal', vmin = minimum, vmax = maximum, extent=[np.min(x), np.max(x), np.min(y), np.max(y)], interpolation='spline16', norm=colors.PowerNorm(gamma=1./3.))
plt.title('..')
plt.xticks(x_ticks)
plt.yticks(y_ticks)
plt.xlabel('${x}$')
plt.ylabel('${y}$')
#plt.colorbar
i += 1
plt.colorbar(I, orientation = 'horizontal').set_label('.')
plt.show()
(编辑:)我尝试遵循this question的一些答案,但是有问题。
所以我拿走了紧密布局并将其添加到代码中
fig.subplots_adjust(bottom = 0.8)
cbar_ax = fig.add_axes([0.35, 0.05, 0.3, 0.03])
fig.colorbar(I, cax=cbar_ax, orientation = 'horizontal').set_label('blabla')
plt.tight_layout()
几乎给了我我想要的东西-图片: 除了它使这两排地块彼此远离。我该如何预防?