Matplotlib 3.0 Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Here is the code block that reads a JPEG file as a pixel-valued list and displays it as an image on the screen:

  1. Read the image louvre.jpg into a three-dimensional array (color images have three channels, whereas black and white images have one channel only):
image = plt.imread('louvre.jpg')
  1. Print the dimensions of the image:
print("Dimensions of the image: ", image.shape)
  1. Plot the image:
plt.imshow(image)
  1. Display the image on the screen:
plt.show()