Complete the code to import the matplotlib module used for plotting images.
import matplotlib.[1] as plt
The pyplot module in matplotlib is used for plotting images and graphs. We import it as plt by convention.
Complete the code to display an image stored in the variable 'img' using imshow.
plt.[1](img)
plt.show()The imshow function is used to display images in matplotlib.
Fix the error in the code to correctly display a grayscale image stored in 'gray_img'.
plt.imshow(gray_img, cmap=[1])
plt.show()To display a grayscale image correctly, the colormap 'gray' must be used.
Fill both blanks to create a figure of size 8x6 inches and display the image 'img'.
plt.figure(figsize=([1], [2])) plt.imshow(img) plt.show()
The figsize parameter takes width and height in inches. Here, 8 and 6 create a wider figure.
Fill all three blanks to display the image 'img' without axis ticks and with a title 'My Image'.
plt.imshow([1]) plt.axis([2]) plt.title([3]) plt.show()
We display the image variable img, turn off axis ticks with 'off', and set the title to 'My Image'.