Get startedGet started for free

Box plot with subgroups

In this exercise, we'll look at the dataset containing responses from a survey given to young people. One of the questions asked of the young people was: "Are you interested in having pets?" Let's explore whether the distribution of ages of those answering "yes" tends to be higher or lower than those answering "no", controlling for gender.

This exercise is part of the course

Introduction to Data Visualization with Seaborn

View Course

Exercise instructions

  • Set the color palette to "Blues".
  • Add subgroups to color the box plots based on "Interested in Pets".
  • Set the title of the FacetGrid object g to "Age of Those Interested in Pets vs. Not".
  • Make the plot display using a Matplotlib function.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Set palette to "Blues"
____

# Adjust to add subgroups based on "Interested in Pets"
g = sns.catplot(x="Gender",
                y="Age", data=survey_data, 
                kind="box", hue=____)

# Set title to "Age of Those Interested in Pets vs. Not"
____

# Show plot
plt.____
Edit and Run Code