Python可视化:python+jupyter notebook展示图片或插入图片

Python可视化:python+jupyter notebook展示图片或插入图片

python+jupyter notebook展示图片或插入图片

有时候,在Jupyter notebook中,我们想要插入一些图片,就像下面的效果一样:
在这里插入图片描述
用到的模块主要是:IPython.display中的Image

from IPython.display import Image
width = 1000
height = 600
Image(filename = 'openstreetmap_figure/openstreetmap_window.jpg', width=width, height=height) 

这样就可实现上面的效果。

Image()函数的详细参数解释

下面是Image()函数的详细参数文档解释。

Image(
    data=None,
    url=None,
    filename=None,
    format=None,
    embed=None,
    width=None,
    height=None,
    retina=False,
    unconfined=False,
    metadata=None,
)
Docstring:      An object that wraps data to be displayed.
Init docstring:
Create a PNG/JPEG/GIF image object given raw data.

When this object is returned by an input cell or passed to the
display function, it will result in the image being displayed
in the frontend.

Parameters
----------
data : unicode, str or bytes
    The raw image data or a URL or filename to load the data from.
    This always results in embedded image data.
url : unicode
    A URL to download the data from. If you specify `url=`,
    the image data will not be embedded unless you also specify `embed=True`.
filename : unicode
    Path to a local file to load the data from.
    Images from a file are always embedded.
format : unicode
    The format of the image data (png/jpeg/jpg/gif). If a filename or URL is given
    for format will be inferred from the filename extension.
embed : bool
    Should the image data be embedded using a data URI (True) or be
    loaded using an <img> tag. Set this to True if you want the image
    to be viewable later with no internet connection in the notebook.

    Default is `True`, unless the keyword argument `url` is set, then
    default value is `False`.

    Note that QtConsole is not able to display images if `embed` is set to `False`
width : int
    Width in pixels to which to constrain the image in html
height : int
    Height in pixels to which to constrain the image in html
retina : bool
    Automatically set the width and height to half of the measured
    width and height.
    This only works for embedded images because it reads the width/height
    from image data.
    For non-embedded images, you can just set the desired display width
    and height directly.
unconfined: bool
    Set unconfined=True to disable max-width confinement of the image.
metadata: dict
    Specify extra metadata to attach to the image.

Examples
--------
# embedded image data, works in qtconsole and notebook
# when passed positionally, the first arg can be any of raw image data,
# a URL, or a filename from which to load image data.
# The result is always embedding image data for inline images.
Image('http://www.google.fr/images/srpr/logo3w.png')
Image('/path/to/image.jpg')
Image(b'RAW_PNG_DATA...')

# Specifying Image(url=...) does not embed the image data,
# it only generates `<img>` tag with a link to the source.
# This will not work in the qtconsole or offline.
Image(url='http://www.google.fr/images/srpr/logo3w.png')
File:           c:\users\hsingluliu\anaconda3\lib\site-packages\ipython\core\display.py
Type:           type
Subclasses:     
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值