0
0
Matplotlibdata~20 mins

Why color matters in visualization in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Color Visualization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What color will the bars be in this plot?
Look at the code below that creates a bar chart. What color will the bars appear?
Matplotlib
import matplotlib.pyplot as plt

values = [5, 7, 3]
labels = ['A', 'B', 'C']

plt.bar(labels, values, color='skyblue')
plt.show()
AThe bars will be sky blue.
BThe bars will be red.
CThe bars will be green.
DThe bars will be black.
Attempts:
2 left
💡 Hint
Check the 'color' parameter in plt.bar function.
data_output
intermediate
1:30remaining
How many unique colors are used in this scatter plot?
This code plots points with different colors. How many unique colors are shown?
Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [10, 15, 13, 17]
colors = ['red', 'blue', 'red', 'green']

plt.scatter(x, y, c=colors)
plt.show()

unique_colors = len(set(colors))
print(unique_colors)
A3
B1
C2
D4
Attempts:
2 left
💡 Hint
Count the different color names in the list.
visualization
advanced
2:00remaining
Which color map best shows data intensity clearly?
You want to show data intensity from low to high using color. Which color map is best for clear understanding?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(0)
data = np.random.rand(10,10)

plt.imshow(data, cmap='viridis')
plt.colorbar()
plt.show()
AGray - only shades of gray, less intuitive for intensity.
BJet - it uses rainbow colors but can be misleading.
CRandom colors - no clear gradient, confusing.
DViridis - it is perceptually uniform and colorblind friendly.
Attempts:
2 left
💡 Hint
Think about color maps that are easy to interpret for all viewers.
🧠 Conceptual
advanced
1:30remaining
Why is choosing colorblind-friendly palettes important?
Why should we use colorblind-friendly palettes in data visualization?
ATo make the plot print better in black and white.
BBecause colorblind-friendly palettes look more colorful.
CTo ensure people with color vision deficiencies can interpret the data correctly.
DBecause they use only primary colors.
Attempts:
2 left
💡 Hint
Think about accessibility and inclusivity.
🔧 Debug
expert
1:30remaining
What error does this code raise related to color usage?
This code tries to plot a line with an invalid color. What error will it raise?
Matplotlib
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [4, 5, 6], color='notacolor')
plt.show()
ATypeError: color must be a string
BValueError: 'notacolor' is not a valid color
CSyntaxError: invalid color argument
DNo error, the plot shows with default color
Attempts:
2 left
💡 Hint
Check matplotlib's error messages for invalid colors.