Bird
0
0

What will be the visual result of this code snippet?

medium📝 Predict Output Q4 of 15
Matplotlib - Image Display
What will be the visual result of this code snippet?
import matplotlib.pyplot as plt
import numpy as np
img = np.arange(9).reshape(3,3)
plt.imshow(img, extent=[0, 6, 0, 3], aspect='auto')
plt.show()
AThe image will stretch to fill the rectangle from x=0 to 6 and y=0 to 3, possibly distorting pixels.
BThe image will display with square pixels ignoring the extent values.
CThe image will be clipped to the default axes limits ignoring extent.
DThe image will appear upside down due to extent values.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze extent

    The extent [0,6,0,3] sets the image bounds in data coordinates.
  2. Step 2: Understand aspect='auto'

    This allows the image to stretch to fill the extent, ignoring pixel aspect ratio.
  3. Final Answer:

    The image will stretch to fill the rectangle from x=0 to 6 and y=0 to 3, possibly distorting pixels. -> Option A
  4. Quick Check:

    Check if aspect='auto' allows distortion [OK]
Quick Trick: Aspect 'auto' stretches image to fit extent [OK]
Common Mistakes:
  • Assuming pixels remain square with aspect='auto'
  • Ignoring extent effect on image size
  • Thinking image is clipped by default axes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes