简体   繁体   English

故障设置 Pandas plot X轴

[英]Trouble setting Pandas plot X-axis

I have the following dataframe:我有以下 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

I would like to plot in on an XY chart where the X axis ticks are the index values and the Y axis ticks represent the range [0, 900].我想 plot 在 XY 图表上,其中 X 轴刻度是索引值,Y 轴刻度代表范围 [0, 900]。 The data in the columns would be plotted accordingly.将相应地绘制列中的数据。 When I currently plot using:当我目前使用 plot 时:

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

I get the following:我得到以下信息:

图形

The Y axis is fine, but the X axis appears to be showing a scaled range of the index values. Y 轴很好,但 X 轴似乎显示了索引值的缩放范围。

How can I make the X axis the actual values of the dataframe index?如何使 X 轴成为 dataframe 索引的实际值? (the curves should start to appear parabolic this way). (曲线应该以这种方式开始出现抛物线)。

Edit:编辑:

This would be the desired output, but with the correct number of ticks:这将是所需的 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