简体   繁体   English

plot 平均线 plot 堆叠条 plot 在 ZF02113237A5A46403E34CEE

[英]plot average line plot of a stacked bar plot in matplotlib

I have a stacked bar chart of this nature done with Matplotlib in python:我在 python 中使用 Matplotlib 完成了这种性质的堆叠条形图: 在此处输入图像描述

Here is my working code:这是我的工作代码:

df.resample("M")["ComName"].value_counts().unstack().rename(lambda  x: x.strftime("%b %Y")).plot(kind="bar", stacked=True, figsize=(20,20), color=color2)

How can I plot the a line plot of the average of each month on top of this plot我怎样才能在这个 plot 之上每月平均的 plot

It should be something like this:它应该是这样的:

s = df.resample("M")["ComName"].value_counts().unstack().rename(lambda x: x.strftime("%b %Y"))
ax = s.plot(kind="bar", stacked=True, figsize=(20,20), color=color2)
ax.plot(s.index, s.mean(1), linewidth=2.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM