Creating histograms
Histograms show the full distribution of a variable. In this exercise, we will display the distribution of weights of medalists in gymnastics and in rowing in the 2016 Olympic games for a comparison between them.
You will have two DataFrames to use. The first is called mens_rowing
and includes information about the medalists in the men's rowing events. The other is called mens_gymnastics
and includes information about medalists in all of the Gymnastics events.
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Use the
ax.hist
method to add a histogram of the"Weight"
column from themens_rowing
DataFrame. - Use
ax.hist
to add a histogram of"Weight"
for themens_gymnastics
DataFrame. - Set the x-axis label to
"Weight (kg)"
and the y-axis label to"# of observations"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
fig, ax = plt.subplots()
# Plot a histogram of "Weight" for mens_rowing
ax.hist(____)
# Compare to histogram of "Weight" for mens_gymnastics
____
# Set the x-axis label to "Weight (kg)"
____
# Set the y-axis label to "# of observations"
____
plt.show()