0
0
Matplotlibdata~10 mins

Multiple images in subplot grid 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 2x2 subplot grid using matplotlib.

Matplotlib
fig, axes = plt.subplots([1], 2)
Drag options to blanks, or click blank then click option'
A2
B4
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 for the number of rows.
Confusing rows and columns.
2fill in blank
medium

Complete the code to display an image on the first subplot.

Matplotlib
axes[0, 0].[1](image1)
Drag options to blanks, or click blank then click option'
Ascatter
Bshow
Cplot
Dimshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot or scatter instead of imshow.
Trying to use show on the axes object.
3fill in blank
hard

Fix the error in the code to remove axis ticks from all subplots.

Matplotlib
for ax in axes.flatten():
    ax.[1]()
Drag options to blanks, or click blank then click option'
Ashow
Bset_axis_off
Cset_visible
Daxis
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis(False) which is invalid.
Using set_visible(False) which hides the whole axes object.
4fill in blank
hard

Fill both blanks to set the title for the second subplot and adjust layout.

Matplotlib
axes[[1]].set_title('Second Image')
plt.[2]()
Drag options to blanks, or click blank then click option'
A[0, 1]
B[1, 0]
Ctight_layout
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong subplot index.
Forgetting to call tight_layout to fix spacing.
5fill in blank
hard

Fill all three blanks to create a dictionary of images with their titles, filter images with width > 100, and display them.

Matplotlib
images = [1]
filtered = {title: img for title, img in images.items() if img.shape[[2]] [3] 100}
for ax, (title, img) in zip(axes.flatten(), filtered.items()):
    ax.imshow(img)
    ax.set_title(title)
plt.tight_layout()
Drag options to blanks, or click blank then click option'
A{'Cat': cat_img, 'Dog': dog_img, 'Bird': bird_img}
B1
C>
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong dictionary syntax.
Using wrong index for image width.
Using wrong comparison operator.