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.
Latihan ini adalah bagian dari kursus
Introduction to Data Visualization with Seaborn
Petunjuk latihan
- Set the color palette to
"Blues". - Add subgroups to color the box plots based on
"Interested in Pets". - Set the title of the
FacetGridobjectgto"Age of Those Interested in Pets vs. Not". - Make the plot display using a Matplotlib function.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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.____