python - Matplotlib Colorbar Display Digtis -


how specify colorbar labels in matplotlib? frequently, need create specific color scales, colorbar labels display poorly can't tell scale is. manually define text next colorbar tick marks, or @ least have them display in scientific notation.

here example plot can't tell bottom 4 color bins represent:

scatter plot ugly legend

and here working example of how plot created:

import numpy np import matplotlib.pyplot plt matplotlib import colors  # mock data x = np.random.random(50) y = np.random.random(50) c = np.arange(0, 1, 1.0/50.0)  # color of points c[0] = 0.00001 c[1] = 0.0001 c[2] = 0.001 c[3] = 0.01 s = 500 * np.random.random(50) + 25  # size of points  # set custom color scaling lcmap = colors.listedcolormap(['#ffffff', '#ff99ff', '#8000ff',                                '#0000ff', '#0080ff', '#58faf4',                                '#00ff00', '#ffff00', '#ff8000',                                '#ff0000']) bounds = [0.0, 0.000001, 0.00001, 0.0001,           0.001, 0.01, 0.1, 0.25, 0.5, 0.75, 1.0] norm = colors.boundarynorm(bounds, lcmap.n)  # create plot fig, ax = plt.subplots() im = ax.scatter(x, y, c=c, s=s, cmap=lcmap, norm=norm)  # add colorbar fig.colorbar(im, ax=ax)  fig.savefig('temp.jpg') 

cbar = fig.colorbar(cax, ticks=[-1, 0, 1]) cbar.ax.set_xticklabels(['low', 'medium', 'high']) 

and use whatever iterable want instead of ['low', 'medium', 'high']

see: http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -