Search code examples
pythonopencvmatplotlibimshow

How to display an image


I tried to use IPython.display with the following code:

from IPython.display import display, Image
display(Image(filename='MyImage.png'))

I also tried to use matplotlib with the following code:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
plt.imshow(mpimg.imread('MyImage.png'))

In both cases, nothing is displayed, not even an error message.


Solution

  • If you are using matplotlib and want to show the image in your interactive notebook, try the following:

    %matplotlib inline
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    img = mpimg.imread('your_image.png')
    imgplot = plt.imshow(img)
    plt.show()