簡體   English   中英

Matplotlib 在大范圍內繪制非常小的 X 軸間隔?

[英]Matplotlib Plotting Very Small X-axis Interval in a big Range?

我的 X 軸數據是這樣的:

 X =[0.0, 0.9, 0.99, 0.999, 0.9999, 0.99999, 0.999999, 0.9999999, 0.99999999, 0.999999999, 0.9999999999, 0.99999999999, 0.999999999999, 0.9999999999999, 0.99999999999999, 1.000000000000001, 1.00000000000001, 1.0000000000001, 1.000000000001, 1.00000000001, 1.0000000001, 1.000000001, 1.00000001, 1.0000001, 1.000001, 1.00001, 1.0001, 1.001, 1.01, 1.1]

我的Y軸數據是這樣的:

Y = [1.0, 3.16227766016838, 9.999999999999995, 31.622776601683782, 100.00000000000551, 316.22776601755754, 999.9999999856221, 3162.277661000621, 9999.999974876204, 31622.777048860404, 99999.99586298171, 316227.7529344374, 1000011.0610435781, 3161786.1272856337, 10003998.786452563, -30011996.35935769, -10003998.786452563, -3163542.1874750517, -999955.5526723525, -316227.7529344374, -99999.99586298171, -31622.77529344374, -10000.000030387355, -3162.2776592452046, -1000.0000000411333, -316.2277660158021, -100.00000000000551, -31.622776601685537, -9.999999999999995, -3.162277660168378]

我想要 plot 這個數據,我應該得到一個曲線圖,但我得到的只是:

plt.plot(X,Y)
plt.show()

#output:

錯誤的繪圖 - 使用 X 和 Y 數據時的圖像

但是當我使用這段代碼時:

​plt.plot(range(30),Y)
plt.show()

#Output:

正確的情節但錯誤的 X 軸刻度

如何獲得 Second Plot 但使用上述列表的 X 數據?

所以這是答案:

import matplotlib
from matplotlib.pyplot import figure
figure(num=None, figsize=(18, 16), dpi=80, facecolor='w', edgecolor='k')
plt.plot(range(29), Y, 'o-')
ax = plt.gca()
fmtr = matplotlib.ticker.IndexFormatter(X)
ax.xaxis.set_major_formatter(fmtr)

#Outputs: 

它是如何需要的

暫無
暫無

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

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