0

Is there a way to stack the bars in countplot so each bar contains two colors.

My code so far:

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()

My current visualization is below along with the stacked graph I am looking to implement.

Current Visualization

Stacked Bar

Heikki
  • 2,214
  • 19
  • 34
ksantana3
  • 1
  • 1
  • 2

1 Answers1

0

You can pass keyword arguments to plt.bar from seaborn.countplot.

You can, therefore use the bottom argument. For example (using 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')

Gives:

bar_plot_example

FChm
  • 2,515
  • 1
  • 17
  • 37