简体   繁体   English

matplotlib 中轴上的尴尬科学计数法

[英]Awkward scientific notation on the axis in matplotlib

So I would like to change the way the numbers are presented on the x and y axis.所以我想改变数字在 x 和 y 轴上的显示方式。 I would either like no powers being represented at all or the powers in each individual tick.我要么不希望任何权力被代表,要么希望每个单独的勾号中的权力。 Is this possible?这可能吗?

indx = np.where(time > 0.28549) # indexs where i want to zoom in
plt.plot(time[indx], dist[indx], label='Without air resistance')
plt.plot(time[indx], distd[indx], label='With air resistance')
plt.xlabel('Time / s')
plt.ylabel('Distance from $y_0$ / m')
plt.ticklabel_format(style='plain')
plt.title('A closer look at the distance-time graph')
plt.legend()
print(time[-1])

graph图形

thanks.谢谢。

You can use the tick formatter您可以使用刻度格式化程序

from matplotlib.ticker import FormatStrFormatter

time = np.linspace(0.285489, 0.285493, 100)
dist = 2*time
distd = 2*time+0.0000025
indx = np.where(time > 0.28549) # indexs where i want to zoom in
plt.plot(time[indx], dist[indx], label='Without air resistance')
plt.plot(time[indx], distd[indx], label='With air resistance')
plt.xlabel('Time / s')
plt.ylabel('Distance from $y_0$ / m')
plt.ticklabel_format(style='plain')

### Format the tick labels, does nothing to the value.
plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%.7f'))
plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.7f'))

plt.title('A closer look at the distance-time graph')
plt.legend()

在此处输入图像描述

As a matter of personal opinion however, I think the matplotlib default looks better because it makes it easier to work out the tick intervals given such a distracting number of decimal places.然而,作为个人意见,我认为 matplotlib 默认值看起来更好,因为考虑到如此令人分心的小数位数,它可以更容易地计算出刻度间隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM