Bird
0
0

What will be the effect of this code snippet?

medium📝 Predict Output Q13 of 15
Matplotlib - Image Display
What will be the effect of this code snippet?
import matplotlib.pyplot as plt
import numpy as np
img = np.ones((10, 20))
plt.imshow(img, extent=[0, 5, 0, 10], aspect='auto')
plt.show()
AImage will be shown with default extent and fixed aspect ratio
BImage will keep original shape and size ignoring extent
CCode will raise an error due to wrong extent format
DImage will stretch to fill x from 0 to 5 and y from 0 to 10, possibly distorted
Step-by-Step Solution
Solution:
  1. Step 1: Analyze extent parameter

    The extent=[0,5,0,10] sets the image to cover x-axis 0 to 5 and y-axis 0 to 10 on the plot.
  2. Step 2: Analyze aspect='auto'

    Aspect='auto' allows the image to stretch to fill the extent box, so the image shape may distort.
  3. Final Answer:

    Image will stretch to fill x from 0 to 5 and y from 0 to 10, possibly distorted -> Option D
  4. Quick Check:

    Extent sets size, aspect='auto' allows stretch [OK]
Quick Trick: Extent sets size; aspect='auto' allows distortion [OK]
Common Mistakes:
  • Assuming extent is ignored
  • Expecting fixed aspect ratio with aspect='auto'
  • Thinking code raises error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes