How to Prevent Matplotlib Plots from Displaying Exponential Notation?

Patricia Arquette
Release: 2024-10-21 20:34:02
Original
630 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!