On Wed, Mar 24, 2010 at 8:03 PM, Angus McMorland <amcm...@gmail.com> wrote: > On 24 March 2010 17:33, Nils Wagner <nwag...@iam.uni-stuttgart.de> wrote: >> Hi all, >> >> how can I change the output format of yticks from 1000000 >> to 1.e6 ? > > I'm not sure if there's an easier way still, but this works: > > from matplotlib.ticker import Formatter > class SciFormatter(Formatter): > def __call__(self, x, pos=None): > return "%0.2e" % x > > ax = plt.gca() > ax.yaxis.set_major_formatter(SciFormatter()) > plt.draw()
There's an easier way to format based on a string: import matplotlib.pyplot as plt #Also available in matplotlib.ticker namespace sci_formatter = plt.FormatStrFormatter('%0.2e') plt.gca().yaxis.set_major_formatter(sci_formatter) plt.draw() You can also make the default formatter (ScalarFormatter) display scientific notation for smaller numbers (the default is anything with an abs() >= 1e7). This displays in a slightly different way, with the base power off to the side of the axis: form = plt.gca().yaxis.get_major_formatter() # so anything with abs() >= 10000 will display in scientific notation form.set_powerlimits((-4, 4)) plt.draw() Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users