簡體   English   中英

matplotlib 中軸上的尷尬科學計數法

[英]Awkward scientific notation on the axis in matplotlib

所以我想改變數字在 x 和 y 軸上的顯示方式。 我要么不希望任何權力被代表,要么希望每個單獨的勾號中的權力。 這可能嗎?

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])

圖形

謝謝。

您可以使用刻度格式化程序

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()

在此處輸入圖像描述

然而,作為個人意見,我認為 matplotlib 默認值看起來更好,因為考慮到如此令人分心的小數位數,它可以更容易地計算出刻度間隔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM