# Formatting numbers in "nicer" scientific notation

2 messages
Open this post in threaded view
|

## Formatting numbers in "nicer" scientific notation

 Hello all, sorry for the vague title, but I didn't know how else to formulate it. I'm looking for a facility to format numbers in a nicer way, namely to turno 3.14e-5 into something like $3.14 \times 10^{\minus 5}$. I'm almost sure I've seen something like that in matplotlib somewhere but I'm not able to find it anymore. Is my recollection wrong? Does anyone know if that is implemented by some other library? Thank you. Cheers, Dan _______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users
Open this post in threaded view
|

## Re: Formatting numbers in "nicer" scientific notation

 Hi Daniele, You might be looking for the MathText-capability of (some of the?) Matplotlib formatters. See for example: - https://matplotlib.org/gallery/ticks_and_spines/scalarformatter.html- https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.ticklabel_format.htmlPlease find attached a small example on how MathText may help to get where you want (if I have understood your goal correctly). Another more advanced fashion may be to write your own formatter with something like FuncFormatter (https://matplotlib.org/api/ticker_api.html#matplotlib.ticker.FuncFormatter) but that would definitively be more work... Hopefully this helps. Best regards, Adrien On 06/29/2018 05:30 PM, Daniele Nicolodi wrote: > Hello all, > > sorry for the vague title, but I didn't know how else to formulate it. > I'm looking for a facility to format numbers in a nicer way, namely to > turno 3.14e-5 into something like $3.14 \times 10^{\minus 5}$. > > I'm almost sure I've seen something like that in matplotlib somewhere > but I'm not able to find it anymore. Is my recollection wrong? Does > anyone know if that is implemented by some other library? > > Thank you. Cheers, > Dan > _______________________________________________ > Matplotlib-users mailing list > [hidden email] > https://mail.python.org/mailman/listinfo/matplotlib-users> _______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users example_mathtext.py (650 bytes) Download Attachment mathtext_ticker.png (22K) Download Attachment