Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Matplotlib - Image Display
Identify the error in this code snippet:
import matplotlib.pyplot as plt
img = [[1,2],[3,4]]
plt.imshow(img)
plt.scatter([0,1], [1,0], color='green')
plt.show()
AImage data must be a NumPy array, not a list
Bplt.scatter coordinates are reversed
CNo error, code runs correctly
DColor 'green' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check image data type

    Matplotlib accepts lists or arrays for imshow(), so list is valid.
  2. Step 2: Verify scatter coordinates and color

    Coordinates and color 'green' are valid; no syntax or runtime error.
  3. Final Answer:

    No error, code runs correctly -> Option C
  4. Quick Check:

    List image + scatter valid = no error [OK]
Quick Trick: Lists can be used as image data in imshow() [OK]
Common Mistakes:
  • Assuming list is invalid image data
  • Thinking color 'green' is unsupported

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes