繁体   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