Matlototlib Axial Labels: Getting Mantissa and Exponent

Is there a way to separately obtain the mantissa and the index of the labels of the axis labels so that I can manipulate how they are displayed? I need them to look like "5x10 -9 " instead of the usual scientific notation "5.0e-9".

If I did this in gnuplot, I would do something like

set format y "%2.0t{/Symbol \327}10^{%L}"

% 2.0t gets me a mantissa, and% L gets me an exponent. How can I do the same in matplotlib?

thank

+3
source share
2 answers

Matplotlib Locators Formatters, () (). ScalarFormatter (useMathText), , .

:

 # import the tickers
 import matplotlib.ticker as mticker

 # your plotting code 

 # create a new formatter and use it on the y-axis
 formatter = mticker.ScalarFormatter(useMathText=True)
 ax.yaxis.set_major_formatter(formatter)

+1

str.split:

In [242]: x
Out[242]: 5e-09

In [243]: '{}*10^{}'.format(*map(int, str(x).split('e')))
Out[243]: '5*10^-9'
0

All Articles