Hi all,
how can I change the output format of yticks from 1000000 to 1.e6 ?
Nils
Hi all,
how can I change the output format of yticks from 1000000 to 1.e6 ?
Nils
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()
Angus.
On 24 March 2010 17:33, Nils Wagner <nwagner@...1052...> wrote:
Hi all,
how can I change the output format of yticks from 1000000
to 1.e6 ?
--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh
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
On Wed, Mar 24, 2010 at 8:03 PM, Angus McMorland <amcmorl@...287...> wrote:
On 24 March 2010 17:33, Nils Wagner <nwagner@...1052...> 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" % xax = plt.gca()
ax.yaxis.set_major_formatter(SciFormatter())
plt.draw()
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma