0
0
Matplotlibdata~20 mins

Named colors and hex codes in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Color Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What color will this plot line be?
Look at the code below. What color will the line be when plotted using matplotlib?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color='navy')
plt.show()
AA dark blue line
BA bright red line
CA black line
DA green line
Attempts:
2 left
💡 Hint
Named colors like 'navy' correspond to specific hex codes representing colors.
data_output
intermediate
2:00remaining
What hex code does this named color represent?
Given the named color 'tomato' in matplotlib, what is its hex code?
Matplotlib
import matplotlib.colors as mcolors
hex_code = mcolors.CSS4_COLORS['tomato']
print(hex_code)
A#ffa500
B#ff4500
C#ff0000
D#ff6347
Attempts:
2 left
💡 Hint
Check the CSS4_COLORS dictionary for the exact hex code.
visualization
advanced
2:00remaining
Identify the color shown by this hex code
This code plots a line with color '#8A2BE2'. What named color does this hex code represent?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1], color='#8A2BE2')
plt.show()
ABlueViolet
BDarkViolet
CMediumPurple
DSlateBlue
Attempts:
2 left
💡 Hint
Look up the hex code '#8A2BE2' in matplotlib's named colors.
🧠 Conceptual
advanced
2:00remaining
Why use named colors instead of hex codes?
Which of the following is the best reason to use named colors like 'crimson' instead of hex codes like '#DC143C' in matplotlib?
ANamed colors always produce brighter colors than hex codes.
BNamed colors are easier to remember and understand than hex codes.
CHex codes are not supported in matplotlib.
DNamed colors use less memory than hex codes.
Attempts:
2 left
💡 Hint
Think about readability and ease of use.
🔧 Debug
expert
2:00remaining
What error does this code raise?
What error will this matplotlib code raise?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], color='#GGHHII')
plt.show()
ANo error, plots with default color
BSyntaxError: invalid hexadecimal literal
CValueError: Invalid RGBA argument
DTypeError: color must be a string
Attempts:
2 left
💡 Hint
Hex codes must contain valid hexadecimal digits (0-9, A-F).