0
0
Matplotlibdata~10 mins

Colorblind-friendly palettes 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 library with the common alias.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Amatplotlib.pyplot
Bmatplotlib
Cpyplot
Dmpl
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'matplotlib' as plt instead of 'matplotlib.pyplot'
Using an uncommon alias like 'mpl'
2fill in blank
medium

Complete the code to create a colorblind-friendly palette using seaborn.

Matplotlib
palette = sns.color_palette("[1]")
Drag options to blanks, or click blank then click option'
Acolorblind
Bdeep
Cpastel
Dbright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'deep' or 'bright' palettes which are not optimized for colorblindness
Misspelling the palette name
3fill in blank
hard

Fix the error in the code to apply a colorblind-friendly palette to a bar plot.

Matplotlib
sns.barplot(x='category', y='value', data=df, palette=[1])
Drag options to blanks, or click blank then click option'
A"colorblind"
Bpalette.colorblind
Ccolorblind
Dsns.color_palette("colorblind")
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the palette name without quotes (syntax error)
Using an undefined variable 'colorblind'
4fill in blank
hard

Fill both blanks to create a dictionary of colors from the colorblind palette for categories 'A' and 'B'.

Matplotlib
colors = {'A': palette[[1]], 'B': palette[[2]]}
Drag options to blanks, or click blank then click option'
A0
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using indexes starting at 1 instead of 0
Using the same index for both categories
5fill in blank
hard

Fill all three blanks to create a scatter plot with colorblind-friendly colors and a legend.

Matplotlib
for cat, color in colors.items():
    subset = df[df['category'] == [1]]
    plt.scatter(subset['x'], subset['y'], color=[2], label=[3])
plt.legend()
Drag options to blanks, or click blank then click option'
Acat
Bcolor
Dsubset
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for filtering or labeling
Mixing up color and category variables