Small multiples with shared y axis
When creating small multiples, it is often preferable to make sure that the different plots are displayed
with the same scale used on the y-axis. This can be configured by setting the sharey
key-word to True
.
In this exercise, you will create a Figure with two Axes objects that share their y-axis. As before, the data is provided in seattle_weather
and austin_weather
DataFrames.
This exercise is part of the course
Introduction to Data Visualization with Matplotlib
Exercise instructions
- Create a Figure with an array of two Axes objects that share their y-axis range.
- Plot Seattle's
"MLY-PRCP-NORMAL"
in a solid blue line in the top Axes. - Add Seattle's
"MLY-PRCP-25PCTL"
and"MLY-PRCP-75PCTL"
in dashed blue lines to the top Axes. - Plot Austin's
"MLY-PRCP-NORMAL"
in a solid red line in the bottom Axes and the"MLY-PRCP-25PCTL"
and"MLY-PRCP-75PCTL"
in dashed red lines.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a figure and an array of axes: 2 rows, 1 column with shared y axis
fig, ax = plt.subplots(2, 1, sharey=True)
# Plot Seattle precipitation data in the top axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)
# Plot Austin precipitation data in the bottom axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)
plt.show()