[英]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.