I have an imshow
plot with a colorbar. I want two labels in the colorbar, one on the left side and the other one on the right side.
This is the 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")
This produces:
I want a second label on the right side of the colorbar. If I use the commented line a second colorbar is added to my plot, and that is not what I want. How can I do this?
You can't have two
label
objects, but you could add a second label usingclb.ax.text
.Also, note that to move the first label to the left hand side, you could use
clb.ax.yaxis.set_label_position('left')
rather thanlabelpad=-40
So, using lines:
Produces this figure: