Home  >  Article  >  Backend Development  >  How to Remove Relative Shifts in Matplotlib Axis Ticks for Absolute Values?

How to Remove Relative Shifts in Matplotlib Axis Ticks for Absolute Values?

DDD
DDDOriginal
2024-10-24 06:33:02742browse

How to Remove Relative Shifts in Matplotlib Axis Ticks for Absolute Values?

Removing Axis Ticks' Relative Shift in Matplotlib

In Matplotlib, plotting against values with large ranges can result in axis ticks with shifts, introducing annotations such as " 1e3." To remove these shifts and obtain absolute tick values, follow these steps:

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

# Capture current axes and retrieve x-axis object
axes = gca()
x_axis = axes.get_xaxis()

# Disable tick offsets for major x-axis formatter
major_formatter = x_axis.get_major_formatter()
major_formatter.set_useOffset(False)

# Refresh plot
draw()</code>

This approach disables the use of offsets in the major tick formatter, ensuring that absolute tick values are displayed. For newer Matplotlib versions (1.4 ), the rcparam axes.formatter.useoffset can be set to False to change the default behavior.

The above is the detailed content of How to Remove Relative Shifts in Matplotlib Axis Ticks for Absolute Values?. 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