【发布时间】:2016-11-02 22:43:12
【问题描述】:
我在 Pandas 中有一个 DataFrame,拆开时看起来像这样
Unique Sessions
Date 2016-06-21 2016-06-29
Name
ABCD 995 4,088
EFGH 8 25
OPEF 1 1
如何让 Pandas 从此 DataFrame 中绘制堆积条形图,其中 x 轴是名称,y 轴是堆叠日期中的数字?
# df is the stacked DataFrame
plot = df.unstack().plot(kind='bar', stacked=True, title="Test")
plot.set_xlabel("Name")
plot.set_ylabel("Num")
plt.savefig('testplot.png', dpi=1000)
此代码将创建一个条形图,但仅考虑 2016-06-21 并且不会将 2016-06-29 的数字叠加到 21 日的数据之上。
【问题讨论】:
标签: python python-3.x pandas matplotlib