Use matplotlib to show the image

Show one image in 5 line

1
2
3
4
5
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
path='/Users/typewind/Desktop/xpy/test.jpg'
img = mpimg.imread(path)
plt.imshow(img)

The output look like this:
Imgur

Turn off the axis

The axis looks not good. So just turn it off by one line:

1
2
3
4
5
6
7
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
path='/Users/typewind/Desktop/xpy/test.jpg'
img = mpimg.imread(path)
# Turn off the axis
plt.axis("off")
plt.imshow(img)