Bird
0
0

You want to overlay a heatmap on a grayscale image so both are visible. Which method correctly achieves this in matplotlib?

hard📝 Application Q8 of 15
Matplotlib - Image Display
You want to overlay a heatmap on a grayscale image so both are visible. Which method correctly achieves this in matplotlib?
ADisplay the grayscale image with <code>plt.imshow()</code> and overlay the heatmap with <code>plt.imshow()</code> using <code>alpha</code> less than 1
BPlot the heatmap first, then the grayscale image without transparency
CUse <code>plt.scatter()</code> to plot heatmap points over the image
DConvert the grayscale image to RGB before plotting the heatmap
Step-by-Step Solution
Solution:
  1. Step 1: Plot base image

    Use plt.imshow() to show the grayscale image.
  2. Step 2: Overlay heatmap

    Use plt.imshow() again for the heatmap with an alpha value (e.g., 0.5) to make it semi-transparent.
  3. Step 3: Result

    This allows both layers to be visible simultaneously.
  4. Final Answer:

    Display the grayscale image with plt.imshow() and overlay the heatmap with plt.imshow() using alpha less than 1 -> Option A
  5. Quick Check:

    Use alpha transparency to combine images [OK]
Quick Trick: Use alpha < 1 to overlay heatmap on image [OK]
Common Mistakes:
  • Plotting heatmap under image without transparency
  • Using scatter instead of imshow for heatmap

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes