Tuesday 6 July 2010

Python Matplotlib: Using Scientific Number Format on Axes

This post will help you with formatting the numbers on axes of your graphs, if you are using Python Matplotlib. When the data you are plotting exceeds a pre-defined value range, Matplotlib will automatically switch to using scientific number formatting.

However, sometimes this can happen a bit erratic or you might want to always use scientific notation (which might be good practice in most cases anyways). This can be done via the following set of commands:

yfm = axScatter.yaxis.get_major_formatter()
yfm.set_powerlimits([ -3, 3])

In order to use these command, matplotlib needs to be included, of course. For plotting examples in Python please refer to the Matplotlib Example Gallery.

No comments:

Post a Comment