0
0
Matplotlibdata~10 mins

Displaying images with imshow 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 matplotlib module used for plotting images.

Matplotlib
import matplotlib.[1] as plt
Drag options to blanks, or click blank then click option'
Aimshow
Bimage
Cplot
Dpyplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'image' instead of 'pyplot' for import.
Trying to import 'imshow' directly.
Using 'plot' which is not the correct module.
2fill in blank
medium

Complete the code to display an image stored in the variable 'img' using imshow.

Matplotlib
plt.[1](img)
plt.show()
Drag options to blanks, or click blank then click option'
Aimshow
Bplot
Cimage
Ddisplay
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'plot' which is for line plots.
Using 'display' which is not a matplotlib function.
Using 'image' which is not a function.
3fill in blank
hard

Fix the error in the code to correctly display a grayscale image stored in 'gray_img'.

Matplotlib
plt.imshow(gray_img, cmap=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'color'
B'gray'
C'rgb'
D'hsv'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rgb' which is for color images.
Using 'color' which is not a valid colormap.
Using 'hsv' which changes colors.
4fill in blank
hard

Fill both blanks to create a figure of size 8x6 inches and display the image 'img'.

Matplotlib
plt.figure(figsize=([1], [2]))
plt.imshow(img)
plt.show()
Drag options to blanks, or click blank then click option'
A8
B6
C4
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping width and height values.
Using very small or very large numbers.
Forgetting to use a tuple.
5fill in blank
hard

Fill all three blanks to display the image 'img' without axis ticks and with a title 'My Image'.

Matplotlib
plt.imshow([1])
plt.axis([2])
plt.title([3])
plt.show()
Drag options to blanks, or click blank then click option'
Aimg
B'off'
C'My Image'
D'on'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'off' for axis.
Passing the title without quotes.
Using wrong variable name for the image.