设置X轴时出现问题

2024-05-20 18:22:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下数据帧:

            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

我想在XY图表上绘图,其中X轴刻度表示索引值,Y轴刻度表示范围[0900]。列中的数据将相应绘制。当前使用以下方式打印时:

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

我得到以下信息:

Graph

Y轴很好,但X轴似乎显示了索引值的缩放范围

如何使X轴成为数据帧索引的实际值?(曲线应开始以这种方式显示为抛物线)

编辑:

这将是所需的输出,但具有正确的刻度数:

enter image description here


Tags: 数据绘图dfplot方式图表绘制plt
2条回答
df.columns = ['xaxis','A','B']
n = np.arange(0,900)
df.plot(x='xaxis',y=n colormap='jet')
plt.show()
# 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)

customized plot

相关问题 更多 >