"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Remove Scientific Notation and Offsets from Matplotlib Plots?

How to Remove Scientific Notation and Offsets from Matplotlib Plots?

Published on 2024-12-22
Browse:391

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]

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3