Bird
Raised Fist0
Matplotlibdata~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. Which type of colormap is best to use when your data has a natural order from low to high values?
easy
A. Sequential colormap
B. Diverging colormap
C. Qualitative colormap
D. Random colormap

Solution

  1. Step 1: Understand data order

    Sequential colormaps are designed for data that goes from low to high in a smooth gradient.
  2. Step 2: Match colormap type to data

    Diverging is for data with a middle point, qualitative is for categories, so sequential fits ordered data best.
  3. Final Answer:

    Sequential colormap -> Option A
  4. Quick Check:

    Ordered data = Sequential colormap [OK]
Hint: Ordered data? Pick sequential colormap [OK]
Common Mistakes:
  • Choosing diverging for ordered data
  • Using qualitative for numeric ranges
  • Thinking random colormap exists
2. Which of the following is the correct way to apply the 'coolwarm' diverging colormap to a matplotlib scatter plot?
easy
A. plt.scatter(x, y, c=z, cmap='coolwarm')
B. plt.scatter(x, y, color='coolwarm')
C. plt.scatter(x, y, cmap='coolwarm')
D. plt.scatter(x, y, c=z, color_map='coolwarm')

Solution

  1. Step 1: Check scatter plot parameters

    The parameter to set colors by data is c=, and colormap is set by cmap=.
  2. Step 2: Identify correct syntax

    plt.scatter(x, y, c=z, cmap='coolwarm') uses both c=z and cmap='coolwarm', which is correct syntax.
  3. Final Answer:

    plt.scatter(x, y, c=z, cmap='coolwarm') -> Option A
  4. Quick Check:

    Use c= for data colors and cmap= for colormap [OK]
Hint: Use c= for data, cmap= for colormap in plots [OK]
Common Mistakes:
  • Using color= instead of c= for data colors
  • Using color_map instead of cmap
  • Omitting c= when using cmap
3. What will be the output colormap type when running this code?
import matplotlib.pyplot as plt
import numpy as np

values = np.array([1, 2, 3, 4, 5])
plt.scatter(values, values, c=values, cmap='tab10')
plt.show()
medium
A. Sequential colormap
B. Diverging colormap
C. Qualitative colormap
D. No colormap applied

Solution

  1. Step 1: Identify the colormap used

    The colormap 'tab10' is a qualitative colormap designed for categorical data.
  2. Step 2: Understand the effect on scatter plot

    Even though values are numeric, using tab10 applies distinct colors for categories, so qualitative colormap is used.
  3. Final Answer:

    Qualitative colormap -> Option C
  4. Quick Check:

    tab10 = Qualitative colormap [OK]
Hint: tab10 means qualitative colormap [OK]
Common Mistakes:
  • Assuming tab10 is sequential
  • Thinking no colormap applied
  • Confusing diverging with qualitative
4. The following code throws an error. What is the mistake?
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1, 1, 10)
y = x**2
plt.scatter(x, y, c=y, cmap='sequential')
plt.show()
medium
A. The variable y cannot be used for colors
B. x and y arrays have different lengths
C. Missing plt.colorbar() call
D. The colormap name 'sequential' is invalid

Solution

  1. Step 1: Check colormap name validity

    Matplotlib does not have a colormap named 'sequential'. It has specific names like 'viridis', 'plasma', etc.
  2. Step 2: Confirm other code parts

    Variables x and y have same length, y can be used for colors, and plt.colorbar() is optional.
  3. Final Answer:

    The colormap name 'sequential' is invalid -> Option D
  4. Quick Check:

    Invalid colormap name causes error [OK]
Hint: Use exact colormap names like 'viridis', not 'sequential' [OK]
Common Mistakes:
  • Using generic names like 'sequential' as colormap
  • Assuming plt.colorbar() is required
  • Thinking y can't be used for colors
5. You want to visualize temperature changes where values below zero are cold, above zero are warm, and zero is neutral. Which colormap type should you choose and why?
hard
A. Sequential, because temperature is ordered from low to high
B. Diverging, because data has a meaningful center at zero
C. Qualitative, because temperature categories are distinct
D. Random, to highlight all values differently

Solution

  1. Step 1: Analyze data characteristics

    Temperature data has a natural center point at zero separating cold and warm values.
  2. Step 2: Match colormap type to data

    Diverging colormaps highlight differences around a center value, perfect for zero-centered data.
  3. Final Answer:

    Diverging, because data has a meaningful center at zero -> Option B
  4. Quick Check:

    Center point data = Diverging colormap [OK]
Hint: Center value? Use diverging colormap [OK]
Common Mistakes:
  • Choosing sequential ignoring center zero
  • Using qualitative for numeric temperature
  • Thinking random colormap exists
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard