Bird
0
0

The following code is intended to overlay a green line on an image, but the line does not appear. What is the error?

medium📝 Debug Q14 of 15
Matplotlib - Image Display
The following code is intended to overlay a green line on an image, but the line does not appear. What is the error?
import matplotlib.pyplot as plt
import numpy as np

image = np.ones((10,10))
plt.imshow(image)
plt.plot([1, 8], [1, 8], color='green')
plt.show()
AThe image is white and the green line is not visible due to default alpha
BThe plot command should be called before imshow
CThe color argument should be 'c' instead of 'color'
DThe coordinates for the line are outside the image bounds
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the image color

    The image is an array of ones, which appears white by default.
  2. Step 2: Check line visibility

    A green line on a white background may be hard to see if the line is thin and no linewidth is set.
  3. Final Answer:

    The image is white and the green line is not visible due to default alpha -> Option A
  4. Quick Check:

    White background hides thin green line [OK]
Quick Trick: Check background and line colors for visibility [OK]
Common Mistakes:
  • Plotting line before image hides image
  • Using wrong color argument name
  • Assuming coordinates are out of bounds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes