0
0
Matplotlibdata~10 mins

GridSpec for complex layouts 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 import the GridSpec class from matplotlib.

Matplotlib
from matplotlib.gridspec import [1]
Drag options to blanks, or click blank then click option'
AGridSpec
BGrid
CSpecGrid
DGridLayout
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import 'Grid' or 'SpecGrid' which do not exist.
Importing from the wrong module.
2fill in blank
medium

Complete the code to create a GridSpec with 3 rows and 2 columns.

Matplotlib
gs = GridSpec([1], 2)
Drag options to blanks, or click blank then click option'
A2
B5
C4
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns.
Using 2 instead of 3 for rows.
3fill in blank
hard

Fix the error in the code to add a subplot that spans the first row across both columns.

Matplotlib
ax = fig.add_subplot(gs[[1]])
Drag options to blanks, or click blank then click option'
A0, :
B0, 0
C0:1, :
D0:2, :
Attempts:
3 left
💡 Hint
Common Mistakes
Using a single index without slicing.
Selecting wrong rows or columns.
4fill in blank
hard

Fill both blanks to create a subplot that covers the bottom two rows and the first column.

Matplotlib
ax = fig.add_subplot(gs[[1], [2]])
Drag options to blanks, or click blank then click option'
A1:
B:2
C0
D0:
Attempts:
3 left
💡 Hint
Common Mistakes
Using :2 which selects rows 0 and 1 instead of bottom rows.
Selecting wrong column index.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each subplot label to its axes object, only for subplots in the first column spanning all rows.

Matplotlib
axes_dict = {label: fig.add_subplot(gs[[1], [2]]) for label in labels if label [3] 'col1'}
Drag options to blanks, or click blank then click option'
A0:
B1
Cin
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong row or column indices.
Using equality instead of containment in the condition.