A. LinearSegmentedColormap requires 'from_list' method to create from colors
B. Colors list must be strings of hex codes only
C. You must import pyplot to create colormaps
D. The colors list cannot have more than two colors
Solution
Step 1: Check how to create colormaps from colors
LinearSegmentedColormap is a class and cannot be called directly with a list. Instead, use the class method from_list.
Step 2: Identify the correct usage
The correct way is LinearSegmentedColormap.from_list('name', colors). The code misses from_list.
Final Answer:
LinearSegmentedColormap requires 'from_list' method to create from colors -> Option A
Quick Check:
Use from_list to create colormap from colors = D [OK]
Hint: Use from_list method to create colormap from colors [OK]
Common Mistakes:
Calling LinearSegmentedColormap directly
Thinking colors must be hex codes
Importing pyplot unnecessarily
5. You want to create a custom colormap that smoothly transitions from blue to white to red, but with the white color occupying the middle 40% of the range. Which approach correctly achieves this?
hard
A. Use LinearSegmentedColormap.from_list('bwr', ['blue', 'white', 'red'])
B. Use LinearSegmentedColormap.from_list('bwr', ['blue', 'white', 'white', 'red'], [0, 0.3, 0.7, 1])
C. Use LinearSegmentedColormap.from_list('bwr', ['blue', 'white', 'red'], [0, 0.5, 1])
D. Use LinearSegmentedColormap.from_list('bwr', ['blue', 'red']) and set midpoint to white separately
Solution
Step 1: Understand color position control in colormaps
To make white occupy the middle 40%, you need to specify positions for colors explicitly.
Step 2: Analyze the options
Use LinearSegmentedColormap.from_list('bwr', ['blue', 'white', 'white', 'red'], [0, 0.3, 0.7, 1]) uses four colors with positions [0, 0.3, 0.7, 1], placing white twice to stretch it over 40% (from 0.3 to 0.7). This creates a smooth transition with white in the middle range.
Final Answer:
Use LinearSegmentedColormap.from_list('bwr', ['blue', 'white', 'white', 'red'], [0, 0.3, 0.7, 1]) -> Option B
Quick Check:
Specify color positions to stretch middle color = C [OK]
Hint: Repeat middle color with positions to stretch it [OK]
Common Mistakes:
Not specifying positions, so white is evenly spread
Using only three colors without position list
Trying to set midpoint color separately
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.