"Step" histogram
Histograms allow us to see the distributions of the data in different groups in our data. In this exercise, you will select groups from the Summer 2016 Olympic Games medalist dataset to compare the height of medalist athletes in two different sports.
The data is stored in a pandas DataFrame object called summer_2016_medals
that has a column "Height". In addition, you are provided a pandas GroupBy object that has been grouped by the sport.
In this exercise, you will visualize and label the histograms of two sports: "Gymnastics" and "Rowing" and see the marked difference between medalists in these two sports.
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Use the
hist
method to display a histogram of the"Weight"
column from themens_rowing
DataFrame, label this as"Rowing"
. - Use
hist
to display a histogram of the"Weight"
column from themens_gymnastics
DataFrame, and label this as"Gymnastics"
. - For both histograms, use the
histtype
argument to visualize the data using the'step'
type and set the number of bins to use to 5. - Add a legend to the figure, before it is displayed.
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
____
# Compare to histogram of "Weight" for mens_gymnastics
____
ax.set_xlabel("Weight (kg)")
ax.set_ylabel("# of observations")
# Add the legend and show the Figure
____
plt.show()