How to Set Tick Label in Scientific Notation in Matplotlib
This post will teach you about using Matplotlib ticklabel_format()
to display ticks label in scientific notation.
Matplotlib Tick Label in Scientific Notation
Too large or too few numbers readily stated in decimal form can be expressed using scientific notation.
First, import the necessary library:
import matplotlib.pyplot as plt
Provide the values along with the x and y axes:
x_val = [1000000, 2000000, 3000000]
y_val = [1, 2, 3]
Let’s plot these numbers using Matplotlib:
plt.plot(x_val, y_val)
plt.ticklabel_format(axis="x", style="sci", scilimits=(0, 0))
Output:
To plot, we use the ticklabel_format()
function, which takes the parameter axes
and style=sci
, which denotes the scientific notation.
Shiv is a self-driven and passionate Machine learning Learner who is innovative in application design, development, testing, and deployment and provides program requirements into sustainable advanced technical solutions through JavaScript, Python, and other programs for continuous improvement of AI technologies.
LinkedInRelated Article - Matplotlib Ticks
- How to Rotate X-Axis Tick Label Text in Matplotlib
- How to Set Tick Labels Font Size in Matplotlib
- How to Hide Axis Text Ticks and/or Tick Labels in Matplotlib
- How to Set Number of Ticks in Matplotlib