簡體   English   中英

故障設置 Pandas plot X軸

[英]Trouble setting Pandas plot X-axis

我有以下 dataframe:

            A                B
0    0.020336         0.017300
1    0.068807         0.042916
2    0.543051         0.261117
3    2.643319         1.208245
4    5.295754         2.425145
5   26.091538        11.936791
6   52.407236        23.968562
7  261.233778       119.663701
8  522.850657       239.565097
9  829.366556       378.151528

我想 plot 在 XY 圖表上,其中 X 軸刻度是索引值,Y 軸刻度代表范圍 [0, 900]。 將相應地繪制列中的數據。 當我目前使用 plot 時:

df.plot(lw=2, colormap='jet', marker='.', markersize=8)
plt.show()

我得到以下信息:

圖形

Y 軸很好,但 X 軸似乎顯示了索引值的縮放范圍。

如何使 X 軸成為 dataframe 索引的實際值? (曲線應該以這種方式開始出現拋物線)。

編輯:

這將是所需的 output,但刻度數正確:

在此處輸入圖像描述

# Save the index to use for labels.
x_values = df.index

# Reset the index to [0, N).
df = df.reset_index(drop=True)

# Plot the re-indexed data.
ax = df.plot(lw=2, colormap='jet', marker='.', markersize=8)

# Use the saved labels.
ax.set_xticklabels(x_values)

自定義情節

df.columns = ['xaxis','A','B']
n = np.arange(0,900)
df.plot(x='xaxis',y=n colormap='jet')
plt.show()

暫無
暫無

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

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