0
0
Matplotlibdata~10 mins

Image colormaps 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 display an image with the 'viridis' colormap.

Matplotlib
import matplotlib.pyplot as plt
import numpy as np

image = np.random.rand(10,10)
plt.imshow(image, cmap=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'cool'
B'viridis'
C'hot'
D'gray'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the colormap name in quotes.
Using a colormap name that does not exist.
2fill in blank
medium

Complete the code to display the image with the 'hot' colormap.

Matplotlib
plt.imshow(image, cmap=[1])
plt.colorbar()
plt.show()
Drag options to blanks, or click blank then click option'
A'hot'
B'spring'
C'cool'
D'winter'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a colormap that does not represent heat.
Not adding quotes around the colormap name.
3fill in blank
hard

Fix the error in the code to correctly apply the 'cividis' colormap.

Matplotlib
plt.imshow(image, cmap=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Acividis
Bcividis()
C'cividis'
D['cividis']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the colormap name without quotes.
Trying to call the colormap as a function.
4fill in blank
hard

Fill both blanks to create a grayscale image with a colorbar.

Matplotlib
plt.imshow(image, cmap=[1])
plt.[2]()
plt.show()
Drag options to blanks, or click blank then click option'
A'gray'
B'viridis'
Ccolorbar
Dshow
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong colormap name for grayscale.
Forgetting to add the colorbar function.
5fill in blank
hard

Fill all three blanks to create a heatmap with 'hot' colormap, add a colorbar, and show the plot.

Matplotlib
plt.imshow(image, cmap=[1])
plt.[2]()
plt.[3]()
Drag options to blanks, or click blank then click option'
A'hot'
Bcolorbar
Cshow
D'cool'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong colormap name.
Forgetting to add colorbar or show the plot.