"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 Relative Shifts in Matplotlib Axis Ticks for Absolute Values?

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

Published on 2025-01-21
Browse:269

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:

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()

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.

Release Statement This article is reprinted at: 1729722472 If there is any infringement, please contact [email protected] to delete it
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