Home >Backend Development >Python Tutorial >How to Prevent Scientific Notation and Offsets in Matplotlib Plots?
Matplotlib offers two formatting options for axes labels:
To disable both offset and scientific notation in a plot:
ax.ticklabel_format(useOffset=False,>
Consider this code:
plt.plot(x, y) plt.show()
With the following input data:
x = np.linspace(1000, 1001, 100) y = np.linspace(1e-9, 1e9, 100)
Initially, the x-axis will have an offset (indicated by a ' ' sign) and the y-axis will use scientific notation (with no ' ' sign).
Using
ax.ticklabel_format(style='plain')
Will disable scientific notation on the y-axis but leave the offset untouched:
[Image of plot with disabled y-axis scientific notation]
Calling
ax.ticklabel_format(useOffset=False)
Removes the offset but preserves scientific notation for the y-axis:
[Image of plot with disabled x-axis offset]
Finally, to disable both, use:
ax.ticklabel_format(useOffset=False,>
[Image of plot with both offset and scientific notation disabled]
The above is the detailed content of How to Prevent Scientific Notation and Offsets in Matplotlib Plots?. For more information, please follow other related articles on the PHP Chinese website!