[英]Plot stacked histogram with grouped DataFrame
plt.hist有一个内置的堆叠标志,您可以设置:
plt.hist(hist_matrix2.column_name, stacked=True)
编辑以回答您的问题,对于长数据(堆叠多个级别),首先需要将数据重组为列表列表:
wide=hist_matrix2.pivot( columns='number', values='column_name')
#This creates many missing values which pandas does not like, so we drop them
widelist=[wide[col].dropna() for col in wide.columns]
# and the stacked graph is here
plt.hist(widelist,stacked=True)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.