Home > Software design >  Change the rotation of a standalone colorbar
Change the rotation of a standalone colorbar

Time:08-18

I have a standalone colorbar that I would like to make vertical :


cb_colors = ["#41fdfe", "blue", "brown", "grey"]
num_colors = len(cb_colors)
cmap_ = matplotlib.colors.ListedColormap(cb_colors)

fig = plt.figure()
ax = fig.add_axes([0.05, 0.80, 0.9, 0.1])

cb = matplotlib.colorbar.ColorbarBase(ax, orientation='horizontal',
                           cmap=cmap_, norm=plt.Normalize( - 0.5 , num_colors - 0.5 ))

cb.set_ticks(range(num_colors))
cb.ax.set_xticklabels(["A", "B", "C", "D"])

I've tried oriental = 'vertical' in matplotlib.colorbar but it doesnt seem to work. I find this as a result enter image description here but I would like this :

enter image description here

Thank you !

CodePudding user response:

Three things you need to do:

  1. change the dimension, the order in enter image description here

  • Related