How can I display an image from a file in Jupyter Notebook?

前端 未结 11 1162
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 01:03

I would like to use an IPython notebook as a way to interactively analyze some genome charts I am making with Biopython\'s GenomeDiagram module. While there is extensive doc

11条回答
  •  Happy的楠姐
    2020-11-28 01:44

    A cleaner Python3 version that use standard numpy, matplotlib and PIL. Merging the answer for opening from URL.

    import matplotlib.pyplot as plt
    from PIL import Image
    import numpy as np
    
    pil_im = Image.open('image.png') #Take jpg + png
    ## Uncomment to open from URL
    #import requests
    #r = requests.get('https://www.vegvesen.no/public/webkamera/kamera?id=131206')
    #pil_im = Image.open(BytesIO(r.content))
    im_array = np.asarray(pil_im)
    plt.imshow(im_array)
    plt.show()
    

提交回复
热议问题