0

I am trying to solve kaggle's titanic competition.

I need to generate a plot where X is representing Sex having male and female as values. And Y as two variables 0 and 1.

From this, I need to see how many males/females survived.

I am trying the following:

sns.barplot(x='Sex', y='Survived', data=train)

But I am getting a plot representing percentage of each male and female:

enter image description here

Any idea how to create stacked bar using seaborn?

I need to plot 2 features, each of them having 2 values.

1 Answer 1

1

I would probably try with "Grouped barplots". Interestingly, the seaborn's gallery page has a nice example about it... with titanic data as an example:

import seaborn as sns
sns.set(style="whitegrid")

# Load the example Titanic dataset
titanic = sns.load_dataset("titanic")

# Draw a nested barplot to show survival for class and sex
g = sns.catplot(x="class", y="survived", hue="sex", data=titanic,
                height=6, kind="bar", palette="muted")
g.despine(left=True)
g.set_ylabels("survival probability")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.