In creating matplotlib figures, you may encounter issues with axis offsets displaying as decimals. For instance, nanosecond measurements show as 4.4e-8 instead of 44e-9 on the y-axis, and day counts appear as 5.54478e4 instead of 55447 on the x-axis.
To resolve this, you can disable offsets for specific axes using a ScalarFormatter with useOffset=False. Here's how:
import matplotlib.pyplot as plt fig, ax = plt.subplots() # Disable offset for y-axis y_formatter = ScalarFormatter(useOffset=False) ax.yaxis.set_major_formatter(y_formatter)
For the x-axis, you can use:
# Disable offset for x-axis x_formatter = ScalarFormatter(useOffset=False) ax.xaxis.set_major_formatter(x_formatter)
With these changes, the axes will display whole numbers for the offsets, as desired.
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