堆叠色相直方图

时间:2020-08-14 00:10:42

标签: matplotlib seaborn facet-grid

抱歉,我没有添加内嵌图像的名声。

这是我发现的代码:

bins = np.linspace(df.Principal.min(), df.Principal.max(), 10)
g = sns.FacetGrid(df, col="Gender", hue="loan_status", palette="Set1", col_wrap=2)
g.map(plt.hist, 'Principal', bins=bins, ec="k")
g.axes[-1].legend()
plt.show()

输出: enter image description here

我想对已有的数据执行类似的操作:

bins = np.linspace(df.overall.min(), df.overall.max(), 10)
g = sns.FacetGrid(df, col="player_positions", hue="preferred_foot", palette="Set1", col_wrap=4)
g.map(plt.hist, 'overall', bins=bins, ec="k")
g.axes[-1].legend()
plt.show()

色调“ preferred_foot”就在左右。

我的输出:

enter image description here

我不确定为什么在绘图中看不到左侧的值

df['preferred_foot'].value_counts()
Right    13960
Left      4318

1 个答案:

答案 0 :(得分:0)

我相当确定这些不是堆叠的直方图,而是两个直方图,一个在另一个之后。我相信您的“左”红色条只是隐藏在“右”蓝色条的后面。

您可以尝试添加一些alpha=0.5或更改色调的顺序(将hue_order=['Right','Left']添加到对FacetGrid的调用中。