Adding error-bars to a bar chart
Statistical plotting techniques add quantitative information for comparisons into the visualization. For example, in this exercise, we will add error bars that quantify not only the difference in the means of the height of medalists in the 2016 Olympic Games, but also the standard deviation of each of these groups, as a way to assess whether the difference is substantial relative to the variability within each group.
For the purpose of this exercise, you will have two DataFrames: mens_rowing
holds data about the medalists in the rowing events and mens_gymnastics
will hold information about the medalists in the gymnastics events.
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Add a bar with size equal to the mean of the
"Height"
column in themens_rowing
DataFrame and an error-bar of its standard deviation. - Add another bar for the mean of the
"Height"
column inmens_gymnastics
with an error-bar of its standard deviation. - Add a label to the the y-axis:
"Height (cm)"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
fig, ax = plt.subplots()
# Add a bar for the rowing "Height" column mean/std
ax.____("Rowing", ____, yerr=____)
# Add a bar for the gymnastics "Height" column mean/std
____
# Label the y-axis
____
plt.show()