0
0
Matplotlibdata~10 mins

Colormaps (sequential, diverging, qualitative) 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 colormap module from matplotlib.

Matplotlib
from matplotlib import [1]
Drag options to blanks, or click blank then click option'
Acm
Bpyplot
Cstyle
Dcolors
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pyplot instead of cm.
Importing colors which is related but not the colormap module.
2fill in blank
medium

Complete the code to create a sequential colormap called 'Blues'.

Matplotlib
cmap = cm.[1]
Drag options to blanks, or click blank then click option'
ASet1
BBlues
Ccoolwarm
DPiYG
Attempts:
3 left
💡 Hint
Common Mistakes
Using diverging colormaps like 'coolwarm' for sequential data.
Using qualitative colormaps like 'Set1' here.
3fill in blank
hard

Fix the error in the code to get a diverging colormap named 'PiYG'.

Matplotlib
div_cmap = cm.[1]
Drag options to blanks, or click blank then click option'
ABlues
Bviridis
CSet3
DPiYG
Attempts:
3 left
💡 Hint
Common Mistakes
Using sequential colormaps for diverging data.
Using qualitative colormaps like 'Set3' instead.
4fill in blank
hard

Fill both blanks to create a qualitative colormap named 'Set1' and apply it to a scatter plot.

Matplotlib
scatter = plt.scatter(x, y, c=labels, cmap=cm.[1])
plt.colorbar(scatter, cmap=cm.[2])
Drag options to blanks, or click blank then click option'
ASet1
Bcoolwarm
Dviridis
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different colormaps for scatter and colorbar.
Using sequential or diverging colormaps for categorical data.
5fill in blank
hard

Fill all three blanks to create a dictionary of colormaps for each type and print the name of the sequential colormap.

Matplotlib
colormaps = {
    'sequential': cm.[1],
    'diverging': cm.[2],
    'qualitative': cm.[3]
}
print(colormaps['sequential'].name)
Drag options to blanks, or click blank then click option'
ABlues
BPiYG
CSet1
Dviridis
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning colormaps to wrong categories.
Using qualitative colormaps as sequential or diverging.