0
0
Matplotlibdata~10 mins

Custom 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 import the module needed to create custom colormaps in matplotlib.

Matplotlib
from matplotlib import [1]
Drag options to blanks, or click blank then click option'
Apyplot
Bcolors
Ccm
Dimage
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'pyplot' instead of 'colors'.
Using 'cm' which is for colormap instances, not creation.
2fill in blank
medium

Complete the code to create a linear segmented colormap from a list of colors.

Matplotlib
custom_cmap = colors.LinearSegmentedColormap.from_list('my_cmap', [1])
Drag options to blanks, or click blank then click option'
A['red', 'green', 'blue']
B'red, green, blue'
C('red', 'green', 'blue')
D{'red', 'green', 'blue'}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string of colors instead of a list.
Using a set or tuple instead of a list.
3fill in blank
hard

Fix the error in the code to correctly create a colormap with three colors.

Matplotlib
cmap = colors.LinearSegmentedColormap.from_list('cmap', ['red', [1], 'blue'])
Drag options to blanks, or click blank then click option'
A'green'
B'yellow'
Cgreen
Dyellow
Attempts:
3 left
💡 Hint
Common Mistakes
Using color names without quotes causing syntax errors.
Using invalid color names.
4fill in blank
hard

Fill both blanks to create a colormap with three colors and use it in a scatter plot.

Matplotlib
cmap = colors.LinearSegmentedColormap.from_list('cmap', ['red', [1], 'blue'])
plt.scatter(x, y, c=z, cmap=[2])
Drag options to blanks, or click blank then click option'
A'yellow'
Bcmap
C'green'
Dcustom_cmap
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the colormap name as a string instead of the variable.
Using wrong color names or missing quotes.
5fill in blank
hard

Fill all three blanks to create a reversed colormap and apply it to an image plot.

Matplotlib
base_cmap = colors.LinearSegmentedColormap.from_list('base', ['blue', [1], 'red'])
reversed_cmap = base_cmap.[2]()
plt.imshow(data, cmap=[3])
Drag options to blanks, or click blank then click option'
A'white'
Breversed
Creversed_cmap
D'reversed'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reverse' instead of 'reversed()' method.
Passing the colormap name as a string instead of the variable.