这是我从matplotlib 示例示例中借用的代码,稍作修改,为带有正确放置标签的图像生成水平颜色条:from matplotlib import colorsimport matplotlib.pyplot as pltimport numpy as npnp.random.seed(19680801)cmap = "cool"fig, axs = plt.subplots()# Generate data with a range that varies from one plot to the next.data = (1 / 10) * np.random.rand(10, 20) * 1e-6image = axs.imshow(data, cmap=cmap)axs.label_outer()# Find the min and max of all colors for use in setting the color scale.vmin = image.get_array().min()vmax = image.get_array().max()norm = colors.Normalize(vmin=vmin, vmax=vmax)cbar = fig.colorbar(image, ax=axs, orientation='horizontal', fraction=.1)cbar.ax.set_ylabel('$[M_\u2609 kpc^{{-2}}]$', position=(30,1), fontsize=20, rotation=0)plt.show()但这是我不想要的输出。我想要一个正好位于colorbar(下方或上方)中心的标签。改变position上面代码中给出的坐标后,在确定标签的位置上似乎没有任何灵活性。在matplotlib颜色条的上下文中,有什么我不知道的吗?非常感谢您的帮助。
添加回答
举报
0/150
提交
取消