Bird
0
0

What will be the output when running this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Image Display
What will be the output when running this code?
import matplotlib.pyplot as plt
import numpy as np
img = np.zeros((3,3))
plt.imshow(img, cmap='gray')
plt.colorbar()
plt.show()
AA 3x3 white image with no colorbar
BAn error because <code>cmap</code> is invalid
CA 3x3 black image with a grayscale colorbar
DA 3x3 colored image with random colors
Step-by-Step Solution
Solution:
  1. Step 1: Understand the image data

    np.zeros((3,3)) creates a 3x3 array of zeros, representing black pixels in grayscale.
  2. Step 2: Analyze plotting commands

    plt.imshow(img, cmap='gray') displays the image in grayscale, and plt.colorbar() adds a color scale bar.
  3. Final Answer:

    A 3x3 black image with a grayscale colorbar -> Option C
  4. Quick Check:

    Zero array + grayscale cmap = black image with colorbar [OK]
Quick Trick: Zeros array with gray cmap shows black image [OK]
Common Mistakes:
  • Assuming zeros array shows white image
  • Thinking cmap='gray' is invalid
  • Ignoring colorbar presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes