Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 向colorbar添加第二个标签_Python 3.x_Matplotlib_Colorbar_Imshow - Fatal编程技术网

Python 3.x 向colorbar添加第二个标签

Python 3.x 向colorbar添加第二个标签,python-3.x,matplotlib,colorbar,imshow,Python 3.x,Matplotlib,Colorbar,Imshow,我有一个带有色条的imshow绘图。我希望在颜色栏中有两个标签,一个在左侧,另一个在右侧 这是mve: V = np.array([[1, 2, 3], [4, 5, 6]]) # Just a sample array plt.imshow(V, cmap = "hot", interpolation = 'none') clb = plt.colorbar() clb.set_label("Firstlabel", fontsize=10, labelpad=-40, y=0.5, ro

我有一个带有色条的
imshow
绘图。我希望在颜色栏中有两个标签,一个在左侧,另一个在右侧

这是mve:

V = np.array([[1, 2, 3], [4, 5, 6]])  # Just a sample array

plt.imshow(V, cmap = "hot", interpolation = 'none')
clb = plt.colorbar()
clb.set_label("Firstlabel", fontsize=10, labelpad=-40, y=0.5, rotation=90)
#clb.set_label("SECONDLABEL") # This is the label I want to add
plt.savefig("Example")
这将产生:


我想在颜色栏的右边再贴一个标签。如果我使用注释线,第二个颜色条将添加到绘图中,这不是我想要的。如何执行此操作?

您不能有两个
标签
对象,但可以使用
clb.ax.text
添加第二个标签

另外,请注意,要将第一个标签移到左侧,可以使用
clb.ax.yaxis.set_label\u position('left')
而不是
labelpad=-40

因此,使用线条:

clb = plt.colorbar()

clb.set_label("Firstlabel", fontsize=10, y=0.5, rotation=90)
clb.ax.yaxis.set_label_position('left')

clb.ax.text(2.5, 0.5, "SECONDLABEL", fontsize=10, rotation=90, va='center') 
生成此图: