How to embed image or picture in jupyter notebook, either from a local machine or from a web resource?

后端 未结 15 1237
天命终不由人
天命终不由人 2020-11-30 16:12

I would like to include image in a jupyter notebook.

If I did the following, it works :

from IPython.display import Image
Image(\"img/picture.png\")
         


        
15条回答
  •  孤街浪徒
    2020-11-30 17:02

    If you want to use the Jupyter Notebook API (and not the IPython one anymore), I find the ipywidgets Jupyter's sub-project. You have an Image widget. Docstring specifies that you have a value parameter which is a bytes. So you can do:

    import requests
    from ipywidgets import Image
    
    Image(value=requests.get('https://octodex.github.com/images/yaktocat.png').content)
    

    I agree, it's simpler to use the Markdown style. But it shows you the Image display Notebook API. You can also resize the image with the width and height parameters.

提交回复
热议问题