Home >Backend Development >Python Tutorial >How to Remove Scientific Notation and Offsets from Matplotlib Plots?

How to Remove Scientific Notation and Offsets from Matplotlib Plots?

Susan Sarandon
Susan SarandonOriginal
2024-12-11 18:23:11293browse

How to Remove Scientific Notation and Offsets from Matplotlib Plots?

Removing Scientific Notation from Matplotlib Plots

You have a plot with scientific notation and an offset on the axes, and you want to eliminate them.

Disabling the Offset

The offset is separate from scientific notation and is added to the numbers displayed on the axis. To disable it, use:

plt.ticklabel_format(useOffset=False)

Disabling Scientific Notation

To prevent scientific notation, use:

plt.ticklabel_format(style='plain')

Disabling Both

To disable both the offset and scientific notation, use:

plt.ticklabel_format(useOffset=False,>

Example

Suppose you have the following code:

import matplotlib.pyplot as plt

plt.plot(range(2003, 2012, 1), range(200300, 201200, 100))
plt.ticklabel_format(useOffset=False)

plt.show()

Which produces this plot:

[Image of plot]

By applying the correct settings, you can eliminate both the offset and scientific notation:

import matplotlib.pyplot as plt

plt.plot(range(2003, 2012, 1), range(200300, 201200, 100))
plt.ticklabel_format(useOffset=False,>

Resulting in this plot:

[Image of plot without scientific notation and offset]

The above is the detailed content of How to Remove Scientific Notation and Offsets from Matplotlib Plots?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn