我有以下数据框:
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轴刻度代表范围[0,900]。列中的数据将相应地绘制。当我当前使用以下方式进行绘制时:
df.plot(lw=2, colormap='jet', marker='.', markersize=8)
plt.show()
我得到以下信息:
Y轴很好,但X轴似乎在显示索引值的缩放范围。
如何使X轴成为数据框索引的实际值? (曲线应开始以这种方式呈抛物线形。)
编辑:
这将是所需的输出,但带有正确的刻度数:
答案 0 :(得分:0)
# 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)
答案 1 :(得分:0)
df.columns = ['xaxis','A','B']
n = np.arange(0,900)
df.plot(x='xaxis',y=n colormap='jet')
plt.show()