Matplotlib basemap colorbar text position

I have a problem with the text position of the color bar. I use matplotlib Basemap to draw some graphics, and I use the colorbar() function.

Now I need to put my color plan to the left of my figure. Therefore, I use location='left' , but the text of ticks and labels is indicated on the right side of the color bar, which overlays part of the image.

Is there a way to change the text on the left side of the panel?

+4
source share
1 answer

Sadly not in a fully integrated way, but most things are possible when you are dealing with an OO build 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, because there were some fundamental changes that made this change less applicable to possible plot types.

To create a color panel with ticks on the left side, you can do something like:

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

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() 

NTN

+7
source

Source: https://habr.com/ru/post/1443118/


All Articles