Bird
0
0

What output will this code produce?

medium📝 Predict Output Q5 of 15
Matplotlib - Image Display
What output will this code produce?
import matplotlib.pyplot as plt
import numpy as np
image = np.ones((2,4))
plt.imshow(image, extent=[0, 4, 0, 2], aspect='equal')
plt.gca().set_xlim(0, 8)
plt.gca().set_ylim(0, 4)
plt.show()
AImage not displayed due to conflicting extent and axis limits.
BImage stretched to fill axes limits 8x4 with non-square pixels.
CImage fills entire plot area with distorted aspect ratio.
DImage with square pixels scaled to 4x2 units, but axes limits doubled, so image appears smaller.
Step-by-Step Solution
Solution:
  1. Step 1: Understand extent and aspect='equal'

    Extent sets image size to 4x2 units with square pixels.
  2. Step 2: Analyze axis limits effect

    Axis limits are set to 8x4, doubling the visible area, so image appears smaller inside plot.
  3. Final Answer:

    Image with square pixels scaled to 4x2 units, but axes limits doubled, so image appears smaller. -> Option D
  4. Quick Check:

    Aspect='equal' keeps pixels square [OK]
Quick Trick: Axis limits can make image appear smaller despite extent [OK]
Common Mistakes:
  • Assuming image fills entire axes
  • Confusing aspect='equal' with stretching
  • Thinking image disappears due to axis limits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes