python - Force use of scientific style for basemap colorbar labels -
string formatting can used specify scientific notation matplotlib.basemap colorbar labels:
cb = m.colorbar(cs, ax=ax1, format='%.4e')
but each label scientifically notated base.
if numbers large enough, colobar automatically reduces them scientific notation, placing base (i.e. x10^n
) @ top of color bar, leaving coefficient numbers labels.
you can standard axis following:
ax.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
is there equivalent method matplotlib.basemap colorbars, or perhaps standard matplotlib colorbar?
there's no one-line method, can updating colorbar's formatter
, calling colorbar.update_ticks()
.
import numpy np import matplotlib.pyplot plt z = np.random.random((10,10)) fig, ax = plt.subplots() im = ax.imshow(z) cb = fig.colorbar(im) cb.formatter.set_powerlimits((0, 0)) cb.update_ticks() plt.show()
the reason odd way of doing things colorbar has statically assigned ticks , ticklabels. colorbar's axes (colorbar.ax
) ranges between 0 , 1. (therefore, altering colorbar.ax.yaxis.formatter
doesn't useful.) tick positions , labels calculated colorbar.locator
, colorbar.formatter
, assigned when colorbar created. therefore, if need precise control on colorbar's ticks/ticklables, need explicitly call colorbar.update_ticks()
after customizing how ticks displayed. colorbar's convenience functions behind scenes, far know, want can't done through method.
Comments
Post a Comment