【发布时间】:2016-07-07 02:18:01
【问题描述】:
我有一个熊猫系列如下:
2014 5668
2015 6024
2016 3903
Name: year, dtype: int64
我尝试绘制一个折线图,其中 x 轴标签是年份,y 轴标签是对应的值。我这样做:
ax = year_counts.plot(kind='line', figsize=[10, 5], marker='o')
ax.yaxis.grid(True)
ax.set_xticklabels(year_counts.index)rotation_mode='anchor', ha='center')
plt.show()
但是当我检查图表时,我看到两个额外的 x 标签,例如:
我不明白为什么会这样。如果我删除带有 set_xticklabels 的行,我不会遇到同样的问题,但是我有 0、1、2 作为标签,而不是 2014、2015 和 2016。
看起来我需要至少五个索引值对来生成一个图(据我所知)。我该如何解决这个问题?
【问题讨论】:
标签: python pandas matplotlib