Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib colorbar ticks on left/opposite side

One could generate a vertical colorbar like so(simplified):

import matplotlib.pyplot as plt import matplotlib as mpl  plt.figure() c_ax=plt.subplot(111) cb = mpl.colorbar.ColorbarBase(c_ax,orientation='vertical') plt.savefig('my_colorbar.png') 

Resulting in something like this(rotated for space reasons):enter image description here

Is it possible to get the ticks labels on the opposite side?

like image 901
M.T Avatar asked Apr 29 '16 13:04

M.T


1 Answers

You can switch the position of the ticks using c_ax.yaxis.set_ticks_position()

So for your example:

import matplotlib.pyplot as plt import matplotlib as mpl  plt.viridis()  fig=plt.figure() c_ax=plt.subplot(199)  cb = mpl.colorbar.ColorbarBase(c_ax,orientation='vertical')  c_ax.yaxis.set_ticks_position('left')  plt.savefig('my_colorbar.png') 

enter image description here

Note you can also move the colorbar label in a similar way:

c_ax.yaxis.set_label_position('left') 

And finally, in case you have a horizontal colorbar, and want to move the ticks and labels to the top, you can use the equivalent function on the xaxis:

c_ax.xaxis.set_label_position('top') c_ax.xaxis.set_ticks_position('top') 
like image 63
tmdavison Avatar answered Sep 19 '22 00:09

tmdavison