Display an image with Python

前端 未结 9 1620
后悔当初
后悔当初 2020-12-23 00:21

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

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

9条回答
  •  攒了一身酷
    2020-12-23 00:45

    Your code:

    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    

    What it should be:

    plt.imshow(mpimg.imread('MyImage.png'))
    File_name = mpimg.imread('FilePath')
    plt.imshow(FileName)
    plt.show()
    

    you're missing a plt.show() unless you're in Jupyter notebook, other IDE's do not automatically display plots so you have to use plt.show() each time you want to display a plot or made a change to an existing plot in follow up code.

提交回复
热议问题