Home  >  Article  >  Backend Development  >  How to Prevent Matplotlib Plots from Displaying Exponential Notation?

How to Prevent Matplotlib Plots from Displaying Exponential Notation?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-21 20:34:02631browse

How to Prevent Matplotlib Plots from Displaying Exponential Notation?

Preventing Exponential Form in Matplotlib Plots

When exploring matplotlib graphs in Figure View, zooming in can trigger the display of x-axis values in exponential notation instead of standard numeric form. To prevent this conversion, follow these steps:

Disable Offset Scaling:

The tick label formatter in matplotlib determines the formatting of x-axis values. By default, it uses a ScalerFormatter, which automatically switches to exponential notation if the visible values display a small fractional change. To disable this offset scaling:

<code class="python">import matplotlib.pyplot as plt

plt.plot(arange(0, 100, 10) + 1000, arange(0, 100, 10))
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.draw()</code>

Disable Scientific Notation:

To completely prevent scientific notation in general, use the following code:

<code class="python">ax.get_xaxis().get_major_formatter().set_scientific(False)</code>

Global Configuration:

To disable offset scaling globally for all matplotlib plots, adjust the 'axes.formatter.useoffset' rcparam:

<code class="python">import matplotlib as mpl

mpl.rcParams['axes.formatter.useoffset'] = False</code>

The above is the detailed content of How to Prevent Matplotlib Plots from Displaying Exponential Notation?. 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