简体   繁体   中英

Trouble setting Pandas plot X-axis

I have the following 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]. The data in the columns would be plotted accordingly. When I currently plot using:

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.

How can I make the X axis the actual values of the dataframe index? (the curves should start to appear parabolic this way).

Edit:

This would be the desired output, but with the correct number of ticks:

在此处输入图像描述

# 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM