Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q6 of 15
Matplotlib - Image Display
What is wrong with this code snippet?
import matplotlib.pyplot as plt
import numpy as np
img = np.array([[1, 2], [3, 4]])
plt.imshow(img, cmap='Blues')
plt.show()
Aplt.show() is missing
BThe array shape is invalid for imshow
CThe colormap name 'Blues' is case-sensitive and should be lowercase 'blues'
DThe numpy array contains invalid data types
Step-by-Step Solution
Solution:
  1. Step 1: Check colormap name

    Matplotlib colormap names are case-sensitive; 'Blues' with uppercase B is valid.
  2. Step 2: Verify colormap validity

    In matplotlib, 'Blues' is a valid colormap, so no error here.
  3. Step 3: Re-examine options

    Array shape is valid, plt.show() is present, and data types are valid integers.
  4. Final Answer:

    None of the above errors exist; the code runs correctly. Since no option correctly states this, the question is flawed but The colormap name 'Blues' is case-sensitive and should be lowercase 'blues' is incorrect as 'Blues' is valid.
  5. Quick Check:

    Check colormap name case sensitivity in matplotlib [OK]
Quick Trick: Colormap names are case-sensitive but 'Blues' is valid [OK]
Common Mistakes:
  • Assuming colormap names are case-insensitive
  • Thinking plt.show() is missing
  • Believing array shape is invalid for imshow

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes