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.
Latihan ini adalah bagian dari kursus
Introduction to Data Visualization with Matplotlib
Petunjuk latihan
- Use the
ax.histmethod to add a histogram of the"Weight"column from themens_rowingDataFrame. - Use
ax.histto add a histogram of"Weight"for themens_gymnasticsDataFrame. - Set the x-axis label to
"Weight (kg)"and the y-axis label to"# of observations".
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
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()