Pandas或Matplotlib中的绘图图

时间:2014-11-12 19:17:26

标签: python matplotlib pandas

我有元组列表[(2014,30,15),(2015,10,20),(2007,5,3)]。   现在我想在pandas中绘制条形图,使得X轴上的每个元组的第一个索引和y轴上的第二个和第三个元素的相应条形。所以对于x轴上的第一个元组2014和y轴上分别为30和15的两个条。如何使用pandas plot函数或在python matplotlib中实现此目的?

1 个答案:

答案 0 :(得分:4)

听起来像你想要的那样:

df = pd.DataFrame( [(2014, 30, 15), (2015, 10, 20), (2007, 5, 3)] )
df.columns = ['year','v1','v2']
df.set_index('year', inplace=True)
df.plot(kind='bar')

给出:

enter image description here