Bird
0
0

Identify the error in this code snippet that tries to display an image:

medium📝 Debug Q14 of 15
Matplotlib - Image Display
Identify the error in this code snippet that tries to display an image:
import matplotlib.pyplot as plt
img = plt.imread('photo.jpg')
plt.imshow(img)
plt.show
Aplt.imshow cannot display JPG images
BIncorrect function to read the image, should use plt.load()
CMissing parentheses after plt.show to display the image
DThe image file path must be absolute
Step-by-Step Solution
Solution:
  1. Step 1: Check the function calls for displaying the image

    plt.show is missing parentheses, so the image will not display.
  2. Step 2: Verify other parts of the code

    plt.imread is correct for reading images, plt.imshow works with JPG, and relative paths are allowed if correct.
  3. Final Answer:

    Missing parentheses after plt.show to display the image -> Option C
  4. Quick Check:

    Always call plt.show() with parentheses [OK]
Quick Trick: plt.show needs () to run and display [OK]
Common Mistakes:
  • Forgetting parentheses on plt.show
  • Using non-existent plt.load() function
  • Thinking JPG images can't be shown
  • Assuming file path must be absolute always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes