![](/img/trans.png)
[英]How to get two legends using pandas plot, one for the colors of the stacked bars and one for the hatches of the bars?
[英]How to plot stacked bars using hist()?
我试图绘制堆积的条形图作为plt.subplots
一部分。 我目前有:
bin_n=100
df_name['column_name'].hist(bins=bin_n, ax=axs[0,1])
并且我想在游戏中添加一个类别(字符串)列。
我的数据集就像:
string_column column_name
'A' 4.3
'A' 4
'B' 4.8
'B' 5
'B' 6.8
我已经阅读了很多堆叠条形的示例,但是它们都使用数组。 所以我的问题是:
我是否需要转换数据集?
我可以使用上述的hist()应用堆叠的钢筋吗? 如果是的话,究竟如何?
df_name.pivot(index='column1', columns='string_column', values='column_name') \
.plot(kind='hist', stacked=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.