How To Get A Graph Axis Into Standard Form
I have plotted a graph where the scale on the y axis is large (10^6) however at the moment the axis is displaying the whole number. How can i get the axis to be displayed in standa
Solution 1:
This can be done by manually setting the format strings for the yticks:
x = plt.linspace(0, 10, 100)
y = 1e6 + plt.sin(x)
ax = plt.subplot(111)
ax.plot(x, y)
ax.set_yticklabels(["{:.6e}".format(t) for t in ax.get_yticks()])
plt.subplots_adjust(left=0.2)
plt.show()
The important part is {:6e}".format(t)
this states we want exponential form (standard form) with 6 S.F. There is also a call to subplots adjust so that the entire length of the number is shown.
EDIT: Having seen your comment I believe you could achieve a similar effect by setting the default params:
plt.rcParams['axes.formatter.limits'] = [-5,5]
The default is [-7, 7]
!
Post a Comment for "How To Get A Graph Axis Into Standard Form"