# Scientific Axis Label with Matplotlib in Python

To set the axis of a plot with matplotlib in Python to scientific formation, an easy way is to use ticklabel_format, the documentation is here.

It is used like this
 import matplotlib.pyplot as plt #ploting something here plt.ticklabel_format(axis='x', style='sci', scilimits=(-2,2)) plt.show() 

where

axis can be ‘x‘, ‘y‘ or ‘both

style can be ‘sci‘ for scientific notation and ‘plain‘ to force plain style.

scilimits specify from what power of 10 scientific notation should be used.

For a working example, see this import matplotlib.pyplot as plt import numpy as np #creating something to plot x=np.arange(start=0, stop=10000, step=100) y=np.random.rand(len(x)) y=x*y #ploting it plt.plot(x,y, 'ro', markersize=12) plt.ticklabel_format(axis='both', style='sci', scilimits=(-2,2)) plt.show() 

## One thought on “Scientific Axis Label with Matplotlib in Python”

1. I was able to find good info from your blog articles.