在Pandas或Matplotlib中绘制图形

2024-03-28 09:48:44 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 函数元素pandas列表plotmatplotlib绘制bar
1条回答
网友
1楼 · 发布于 2024-03-28 09:48:44

听起来像你想要的:

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

相关问题 更多 >