我的df
包含三列每月数据。 Here是文件。
我想使用堆叠式条形图在子图中将每个月的所有三列都放在顶部。
这是我尝试过的许多代码之一:
df.plot(kind='bar', stacked=True, bottom = df['Yf'])
我想将其放在子图中,所有列都堆叠在一起。因此,每个月的最高点是对应月份中三个参数的总和。我还想自由地安排哪个参数应该放在底部,中间和顶部。
我想要这样的东西。
在互联网上搜索,尚无解决方案。
答案 0 :(得分:1)
删除bottom=df['Yf']
,因为这告诉plt
将条形图放置在df['Yf']
的高度。因此:
df.plot(kind='bar', stacked=True)
您可以选择顺序(bottom, middle, top)
,如下所示:
orders = ['Yf', 'Ls', 'Lc']
df[orders].plot(kind='bar', stacked=True)
将Yf
放在底部,然后将Ls
和Lc
放在顶部。输出:
答案 1 :(得分:0)