Home > Backend Development > Python Tutorial > How to Disable Axis Tick Relative Shift in Matplotlib?

How to Disable Axis Tick Relative Shift in Matplotlib?

DDD
Release: 2024-10-24 06:22:31
Original
733 people have browsed it

How to Disable Axis Tick Relative Shift in Matplotlib?

Removing Axis Tick Relative Shift in Matplotlib

When dealing with graphs displaying numeric ranges spanning significant values, matplotlib assigns a relative shift syntax ( 1e3 in this case) to the axis ticks. For instance, with the plot:

<code class="python">plot([1000, 1001, 1002], [1, 2, 3])</code>
Copy after login

The x-axis ticks might appear as:

0.0     0.5     1.0     1.5     2.0
+1e3
Copy after login

To eliminate the relative shift and obtain ticks like:

1000.0  1000.5  1001.0  1001.5  1002.0
Copy after login

Follow these steps:

<code class="python">plot([1000, 1001, 1002], [1, 2, 3])
gca().get_xaxis().get_major_formatter().set_useOffset(False)
draw()</code>
Copy after login

This technique involves retrieving the active axes, obtaining the x-axis axis object, and then accessing the major formatter. By setting the useOffset attribute to False, the relative shift is disabled.

Alternatively, in matplotlib versions 1.4 and later, you can modify the default behavior by adjusting the axes.formatter.useoffset parameter:

<code class="python">rcParams.update({'axes.formatter.useoffset': False})</code>
Copy after login

The above is the detailed content of How to Disable Axis Tick Relative Shift in Matplotlib?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template