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.random.rand(4,4)
plt.imshow(img, extent=[0, 4, 4])
plt.show()
AThe image array shape is incompatible with <code>imshow</code>.
BThe <code>extent</code> list has an incorrect number of elements; it must have four values.
CThe <code>plt.show()</code> call is missing parentheses.
DThe <code>extent</code> values must be integers only.
Step-by-Step Solution
Solution:
  1. Step 1: Check extent parameter

    The extent argument requires exactly four values: [left, right, bottom, top].
  2. Step 2: Identify the error

    The code provides only three values: [0, 4, 4], which is invalid.
  3. Final Answer:

    The extent list has an incorrect number of elements; it must have four values. -> Option B
  4. Quick Check:

    Count extent elements; must be four [OK]
Quick Trick: Extent must have four numeric values [OK]
Common Mistakes:
  • Providing fewer or more than four extent values
  • Confusing image shape with extent length
  • Assuming extent values must be integers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes