需要在堆叠的直方图上使用不透明或透明的颜色并添加图例

问题描述 投票:0回答:1

我想使直方图上的颜色不透明,并且想在图上添加图例。我已经看到了很多资源,但是我在直方图中使用了groupby方法。我不确定如何为groupby的每个因素添加颜色

sia_table.groupby('subreddit')['sia_compound'].hist(bins = 20)
python matplotlib jupyter-notebook
1个回答
0
投票

我建议使用subplots创建一个轴,然后将绘图映射到它。

fig, ax = plt.subplots(1,1,figsize=(10,4))
sia_table.groupby('subreddit')['sia_compound'].hist(alpha=0.5, ax=ax)
ax.legend(sia_table['subreddit'].unique())
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.