Pandas中的多个索引和图形

时间:2015-07-21 15:31:39

标签: python pandas

我有一个如下所示的数据框:

Species      POAPRA   AGGREP
R2             1        2  
D1             5        8
D2             4        5

我希望使用以下代码制作它的图表:

ax=df.plot(title='Invasive Species')
ax.set_xlabel('Departure Level')
ax.set_ylabel('Percent Occurance')

产生

enter image description here

问题是我想让x轴显示R1,D1和D2而不是0,0.5,1.0,1.5和2.0。我很确定我需要将第一列设置为索引,但由于我有多个索引,我不知道该怎么做。

1 个答案:

答案 0 :(得分:2)

在绘图之前,只需set_indexSpecies

ax=df.set_index('Species').plot(title='Invasive Species')
ax.set_xlabel('Departure Level')
ax.set_ylabel('Percent Occurance')

enter image description here