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.
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