I have the following code:
plt.plot(range(2003,2012,1),range(200300,201200,100))
# several solutions from other questions have not worked, including
# plt.ticklabel_format(style='sci', axis='x', scilimits=(-1000000,1000000))
# ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.show()
which produces the following plot:
How do I prevent scientific notation here? Is ticklabel_format broken? does not resolve the issue of actually removing the offset.
plt.plot(np.arange(1e6, 3 * 1e7, 1e6))
plt.ticklabel_format(useOffset=False)
Best Answer
In your case, you're actually wanting to disable the offset. Using scientific notation is a separate setting from showing things in terms of an offset value.
However,
ax.ticklabel_format(useOffset=False)
should have worked (though you've listed it as one of the things that didn't).For example:
If you want to disable both the offset and scientific notaion, you'd use
ax.ticklabel_format(useOffset=False, style='plain')
.Difference between "offset" and "scientific notation"
In matplotlib axis formatting, "scientific notation" refers to a multiplier for the numbers show, while the "offset" is a separate term that is added.
Consider this example:
The x-axis will have an offset (note the
+
sign) and the y-axis will use scientific notation (as a multiplier -- No plus sign).We can disable either one separately. The most convenient way is the
ax.ticklabel_format
method (orplt.ticklabel_format
).For example, if we call:
We'll disable the scientific notation on the y-axis:
And if we call
We'll disable the offset on the x-axis, but leave the y-axis scientific notation untouched:
Finally, we can disable both through: