Add units to plots?

I have several plots where the scientific notation exponential
overflows to the top of the plot like this:
http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html.

Is there any way to add units to this? So that, if I wanted, the
units would show up in the overflow as: 1e8 m^3 , for meters cubed?

Also, is there an easy way to add units to the numbers on the x or y
axis in general? Thanks.

                                 Joseph Smidt

···

--
------------------------------------------------------------------------
Joseph Smidt <josephsmidt@...287...>

Physics and Astronomy
4129 Frederick Reines Hall
Irvine, CA 92697-4575
Office: 949-824-3269

You can use a custom formatter, eg::

  from matplotlib.ticker import FormatStrFormatter
  ax.xaxis.set_major_formatter(r'%\.4fm^3&#39;) # using mathtext for the
m^3 exponent

See

  http://matplotlib.sourceforge.net/api/ticker_api.html#matplotlib.ticker.FormatStrFormatter

and some code examples

  Search — Matplotlib 3.8.2 documentation

JDH

···

On Tue, Jul 7, 2009 at 4:06 PM, Joseph Smidt<josephsmidt@...287...> wrote:

I have several plots where the scientific notation exponential
overflows to the top of the plot like this:
http://matplotlib.sourceforge.net/examples/pylab_examples/plotfile_demo.html.

Is there any way to add units to this? So that, if I wanted, the
units would show up in the overflow as: 1e8 m^3 , for meters cubed?

Also, is there an easy way to add units to the numbers on the x or y
axis in general? Thanks.