0
0
Matplotlibdata~20 mins

Colormaps (sequential, diverging, qualitative) in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Colormap Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Sequential Colormap Gradient Plot
What will be the color of the middle bar in this horizontal bar plot using the 'Blues' sequential colormap?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

values = np.linspace(0, 1, 5)
colors = plt.cm.Blues(values)

plt.barh(range(5), [1]*5, color=colors)
plt.show()

# Question: What color corresponds to the middle bar (index 2) in terms of blue intensity?
AA medium blue, clearly visible but not dark
BA very light blue, close to white
CA very dark blue, almost navy
DPure white
Attempts:
2 left
💡 Hint
Sequential colormaps go from light to dark as values increase from 0 to 1.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Diverging Colormaps
Why are diverging colormaps useful in data visualization?
AThey only use shades of gray to represent data.
BThey highlight differences from a central neutral value, showing two extremes distinctly.
CThey assign random colors to categories without order.
DThey show a smooth gradient from light to dark of a single color.
Attempts:
2 left
💡 Hint
Think about data that has a meaningful midpoint like zero or average.
visualization
advanced
2:30remaining
Identify Qualitative Colormap Usage
Which plot correctly uses a qualitative colormap to display categorical data?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

categories = ['A', 'B', 'C', 'D']
values = [5, 7, 3, 4]
colors = plt.cm.Set3(np.linspace(0, 1, 4))

plt.bar(categories, values, color=colors)
plt.show()
AA bar plot with distinct colors for each category using 'Set3' colormap
BA line plot with a gradient color from light to dark blue
CA heatmap using 'coolwarm' diverging colormap
DA scatter plot with colors representing a continuous variable
Attempts:
2 left
💡 Hint
Qualitative colormaps are best for categories without order.
🔧 Debug
advanced
2:00remaining
Error in Using Colormap for Continuous Data
What error or issue will occur with this code snippet?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

values = np.array([1, 2, 3, 4])
colors = plt.cm.Set3(values / 4)

plt.scatter(values, values, color=colors)
plt.show()
AValueError because 'colors' array shape is incorrect
BNo error, plot shows correctly with distinct colors
CValueError because 'Set3' expects values between 0 and 1, but got integers
DRuntimeWarning about deprecated colormap usage
Attempts:
2 left
💡 Hint
Colormaps expect input values normalized between 0 and 1.
🚀 Application
expert
3:00remaining
Choosing the Best Colormap for Temperature Anomaly Data
You have temperature anomaly data ranging from -5 to +5 degrees. Which colormap choice best helps visualize both negative and positive anomalies clearly?
AUse a sequential colormap like 'Blues' from light to dark blue
BUse a grayscale colormap from black to white
CUse a qualitative colormap like 'Pastel1' with distinct colors
DUse a diverging colormap like 'coolwarm' centered at zero
Attempts:
2 left
💡 Hint
Think about data with meaningful midpoint zero and two extremes.