【问题标题】:Seaborn stacking bars in multiple countplots located within a subplot [duplicate]位于子图中的多个计数图中的Seaborn堆叠条[重复]
【发布时间】:2019-07-15 19:46:50
【问题描述】:

有没有办法在countplot 中堆叠条形图,所以每个条形图都包含两种颜色。

到目前为止我的代码:

fig, axes = plt.subplots(4, 4, figsize=(15,13), sharex=True)
axes = axes.flatten()
object_bol = df.dtypes == 'object'
for ax, catplot in zip(axes, df.dtypes[object_bol].index):
    sns.countplot(y=catplot, data=df, ax=ax, hue = "Attrition")

plt.tight_layout()  
plt.show()

下面是我当前的可视化以及我希望实现的堆叠图。

【问题讨论】:

  • 嗨 ksantana3。为了帮助我们帮助您,请您提供您的数据集或其中的一部分。

标签: python seaborn


【解决方案1】:

You can pass keyword argumentsplt.barseaborn.countplot

因此,您可以使用bottom 参数。例如(使用plt.bar):

 x = np.arange(0,11,1)
 y = x**2

plt.bar(x, y)
plt.bar(x, y, bottom=y)
plt.xlabel('x')
plt.ylabel('y')

给予:

【讨论】:

    猜你喜欢
    • 2018-10-23
    • 2019-12-29
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 1970-01-01
    相关资源
    最近更新 更多