Bird
0
0

Identify the mistake in this code snippet that attempts to display an image:

medium📝 Debug Q7 of 15
Matplotlib - Image Display
Identify the mistake in this code snippet that attempts to display an image:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('photo.jpg')
plt.imshow(img)
plt.colorbar
plt.show()
AThe image file path is incorrect
BThe <code>plt.colorbar</code> function is not called with parentheses
CThe <code>imshow</code> function cannot display JPEG images
DThe <code>mpimg.imread</code> function does not load images
Step-by-Step Solution
Solution:
  1. Step 1: Review function calls

    Functions like plt.colorbar require parentheses to execute.
  2. Step 2: Identify the error

    In the code, plt.colorbar is referenced but not called (plt.colorbar() is needed).
  3. Final Answer:

    The plt.colorbar function is not called with parentheses -> Option B
  4. Quick Check:

    Check all function calls include parentheses [OK]
Quick Trick: Always use parentheses to call functions in matplotlib [OK]
Common Mistakes:
  • Forgetting parentheses on function calls
  • Assuming imread cannot read JPEG files
  • Misunderstanding matplotlib image display capabilities

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes