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
import numpy as np
image = np.array([[1, 2], [3, 4]])
plt.imshow(image, cmap=plasma)
plt.show()
Aplt.show() is missing
BThe image array shape is invalid
CThe numpy array should be float type
DThe colormap 'plasma' should be a string: cmap='plasma'
Step-by-Step Solution
Solution:
  1. Step 1: Check how colormap is passed

    The code passes cmap=plasma without quotes, but 'plasma' must be a string.
  2. Step 2: Confirm correct syntax

    Correct usage is cmap='plasma' to specify the colormap name as a string.
  3. Final Answer:

    The colormap 'plasma' should be a string: cmap='plasma' -> Option D
  4. Quick Check:

    Colormap must be string in quotes [OK]
Quick Trick: Always quote colormap names in cmap parameter [OK]
Common Mistakes:
  • Passing colormap as variable without quotes
  • Thinking image shape causes error
  • Forgetting plt.show()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes