0
0
Matplotlibdata~10 mins

Subplot spacing adjustment in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a figure with 2 subplots arranged vertically.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1)
plt.[1]()
plt.show()
Drag options to blanks, or click blank then click option'
Atight_layout
Bshow
Csubplot
Dfigure
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.show() instead of plt.tight_layout() before showing the plot.
Calling plt.subplot() which creates a single subplot, not adjusting spacing.
2fill in blank
medium

Complete the code to adjust horizontal space between subplots using subplots_adjust.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2)
fig.subplots_adjust([1]=0.5)
plt.show()
Drag options to blanks, or click blank then click option'
Atop
Bwspace
Chspace
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'hspace' which controls vertical spacing instead of horizontal.
Using 'top' or 'left' which control figure edges, not spacing between subplots.
3fill in blank
hard

Fix the error in the code to adjust vertical space between subplots.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 1)
fig.subplots_adjust([1]=0.3)
plt.show()
Drag options to blanks, or click blank then click option'
Awspace
Bwidth
Chspace
Dheight
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wspace' which adjusts horizontal spacing.
Using 'width' or 'height' which are not valid parameters for subplots_adjust.
4fill in blank
hard

Fill both blanks to create subplots and adjust both horizontal and vertical spacing.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)
fig.subplots_adjust([1]=0.4, [2]=0.6)
plt.show()
Drag options to blanks, or click blank then click option'
Awspace
Bhspace
Cleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' or 'right' which control figure edges, not spacing.
Mixing up 'wspace' and 'hspace' parameters.
5fill in blank
hard

Fill all three blanks to create subplots, adjust spacing, and set a title for the figure.

Matplotlib
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 1)
fig.subplots_adjust([1]=0.5, [2]=0.4)
fig.[3]('My Subplots')
plt.show()
Drag options to blanks, or click blank then click option'
Awspace
Bhspace
Csuptitle
Dtitle
Attempts:
3 left
💡 Hint
Common Mistakes
Using title which sets title for individual subplots, not the figure.
Mixing up wspace and hspace values.