matplotlib basemap colorbar text position

matplotlib basemap colorbar text position,matplotlib,colorbar,matplotlib-basemap,Matplotlib,Colorbar,Matplotlib Basemap,I have a problem about the text position of the colorbar. I'm using matplotlib Basemap to make some plots, and I the use colorbar() function. Now I need to put my colorbar on the left side of my figure. So I use location='left', but the text of ticks and label are given on the right side of the colorbar, which overlay part of the picture. Is there any way to change the text on the left side of the bar?

I have a problem about the text position of the colorbar. I'm using matplotlib Basemap to make some plots, and I the use

colorbar()
function.

Now I need to put my colorbar on the left side of my figure. So I use

location='left'
, but the text of ticks and label are given on the right side of the colorbar, which overlay part of the picture.

Is there any way to change the text on the left side of the bar?


#1

Sadly not in an entirely integrated way, but most things are possible when you are dealing with an OO plotting library such as mpl.

I worked on a change that implemented this functionality in a more accessible form about 3 months ago (https://github.com/matplotlib/matplotlib/pull/956), but we decided not to merge it as there were some fundamental changes going on that made this change less applicable to may types of plot.

To produce the colorbar with ticks on the left hand side, you could do something like:

<your_colorbar_instance>.ax.yaxis.set_ticks_position('left')

A real working example:

import matplotlib
# create a dummy scalar mappable to create a colour bar with:
sm = plt.cm.ScalarMappable(cmap=plt.get_cmap('Reds'))
sm.set_array(range(10))

# create the colorbar and put the ticks on the left hand side
cb = plt.colorbar(sm)
cb.ax.yaxis.set_ticks_position('left')

plt.show()

HTH,


#2

@innu: Did this help at all?

#3

It certainly helped me so thank you! What about moving the colourbar label to the left side however?

#4

Actually don't worry... <your_colorbar_instance>.ax.yaxis.set_label_position('left')