如何将直方图中的蓝色条带到最前面? [英] How to bring the blue bars in this histogram plot to the front?

查看:77
本文介绍了如何将直方图中的蓝色条带到最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有代码可以将直方图中的蓝色条带到最前面?如果删除Alpha,则根本看不到蓝色条.我正在使用Python3和Seaborn进行绘图

Is there a code that can bring the blue bars in this histogram plot to the front? If I remove alpha I can't see the blue bars at all. I'm using Python3 and Seaborn for this plot

提前谢谢

g = sns.FacetGrid(df, hue='credit.policy', palette='coolwarm', height =5, aspect=2)
g = g.map(plt.hist, 'fico', alpha=0.8, bins=30).add_legend()

推荐答案

如@ trenton-mckinney所建议,您可以使用hue_order控制类别的绘制顺序.比较:

As suggested by @trenton-mckinney, you can use hue_order to control the order in which your categories are plotted. Compare:

df = pd.concat([pd.DataFrame({'data':np.random.normal(loc=0, scale=0.25, size=(1000,)), 'category':0}),pd.DataFrame({'data':np.random.normal(loc=1, size=(1000,)), 'category':1})])



g = sns.FacetGrid(df, hue='category', palette='coolwarm', height=5, aspect=2, hue_order=[0,1])
g = g.map(plt.hist, 'data', alpha=0.8, bins=30).add_legend()

g = sns.FacetGrid(df, hue='category', palette='coolwarm', height=5, aspect=2, hue_order=[1,0])
g = g.map(plt.hist, 'data', alpha=0.8, bins=30).add_legend()

这篇关于如何将直方图中的蓝色条带到最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆