Bar plots with percentages
Let's continue exploring the responses to a survey sent out to young people. The variable "Interested in Math"
is True
if the person reported being interested or very interested in mathematics, and False
otherwise. What percentage of young people report being interested in math, and does this vary based on gender? Let's use a bar plot to find out.
As a reminder, we'll create a bar plot using the catplot()
function, providing the name of categorical variable to put on the x-axis (x=____
), the name of the quantitative variable to summarize on the y-axis (y=____
), the pandas DataFrame to use (data=____
), and the type of categorical plot (kind="bar"
).
Seaborn has been imported as sns
and matplotlib.pyplot
has been imported as plt
.
This is a part of the course
“Introduction to Data Visualization with Seaborn”
Exercise instructions
- Use the
survey_data
DataFrame andsns.catplot()
to create a bar plot with"Gender"
on the x-axis and"Interested in Math"
on the y-axis.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a bar plot of interest in math, separated by gender
# Show plot
plt.show()
This exercise is part of the course
Introduction to Data Visualization with Seaborn
Learn how to create informative and attractive visualizations in Python using the Seaborn library.
Categorical variables are present in nearly every dataset, but they are especially prominent in survey data. In this chapter, you will learn how to create and customize categorical plots such as box plots, bar plots, count plots, and point plots. Along the way, you will explore survey data from young people about their interests, students about their study habits, and adult men about their feelings about masculinity.
Exercise 1: Count plots and bar plotsExercise 2: Count plotsExercise 3: Bar plots with percentagesExercise 4: Customizing bar plotsExercise 5: Box plotsExercise 6: Create and interpret a box plotExercise 7: Omitting outliersExercise 8: Adjusting the whiskersExercise 9: Point plotsExercise 10: Customizing point plotsExercise 11: Point plots with subgroupsWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.