Module: display — IPython 4.0.0 documentation

# Module: `display`

Public API for display tools in IPython.

## 18 Classes

class `IPython.display.` `Audio`(data=None, filename=None, url=None, embed=None, rate=None, autoplay=False)

  Bases: `IPython.core.display.DisplayObject`

  Create an audio object.

  When this object is returned by an input cell or passed to the display function, it will result in Audio controls being displayed in the frontend (only works in the notebook).

  Parameters: | data : numpy array, list, unicode, str or bytes Can be one of Numpy 1d array containing the desired waveform (mono) Numpy 2d array containing waveforms for each channel. Shape=(NCHAN, NSAMPLES). For the standard channel order, see http://msdn.microsoft.com/en-us/library/windows/hardware/dn653308(v=vs.85).aspx List of float or integer representing the waveform (mono) String containing the filename Bytestring containing raw PCM data or URL pointing to a file on the web. If the array option is used the waveform will be normalized. If a filename or url is used the format support will be browser dependent. url : unicode A URL to download the data from. filename : unicode Path to a local file to load the data from. embed : boolean Should the image data be embedded using a data URI (True) or should the original source be referenced. Set this to True if you want the audio to playable later with no internet connection in the notebook. Default is `True`, unless the keyword argument `url` is set, then default value is `False`. rate : integer The sampling rate of the raw data. Only required when data parameter is being used as an array autoplay : bool Set to True if the audio should immediately start playing. Default is `False`.

  Examples

      # Generate a sound
      import numpy as np
      framerate = 44100
      t = np.linspace(0,5,framerate*5)
      data = np.sin(2*np.pi*220*t) + np.sin(2*np.pi*224*t))
      Audio(data,rate=framerate)

      # Can also do stereo or more channels
      dataleft = np.sin(2*np.pi*220*t)
      dataright = np.sin(2*np.pi*224*t)
      Audio([dataleft, dataright],rate=framerate)

      Audio("http://www.nch.com.au/acm/8k16bitpcm.wav")  # From URL
      Audio(url="http://www.w3schools.com/html/horse.ogg")

      Audio('/path/to/sound.wav')  # From file
      Audio(filename='/path/to/sound.ogg')

      Audio(b'RAW_WAV_DATA..)  # From bytes
      Audio(data=b'RAW_WAV_DATA..)

  `__init__`(data=None, filename=None, url=None, embed=None, rate=None, autoplay=False)
  `reload`()

    Reload the raw data from file or URL.

class `IPython.display.` `DisplayObject`(data=None, url=None, filename=None)

  Bases: `object`

  An object that wraps data to be displayed.

  `__init__`(data=None, url=None, filename=None)

    Create a display object given raw data.

    When this object is returned by an expression or passed to the display function, it will result in the data being displayed in the frontend. The MIME type of the data should match the subclasses used, so the Png subclass should be used for ‘image/png’ data. If the data is a URL, the data will first be downloaded and then displayed. If

    Parameters: | data : unicode, str or bytes The raw data or a URL or file to load the data from url : unicode A URL to download the data from. filename : unicode Path to a local file to load the data from.

  `reload`()

    Reload the raw data from file or URL.

class `IPython.display.` `FileLink`(path, url_prefix='', result_html_prefix='', result_html_suffix='<br>')

  Bases: `object`

  Class for embedding a local file link in an IPython session, based on path

  e.g. to embed a link that was generated in the IPython notebook as my/data.txt

  you would do:

      local_file = FileLink("my/data.txt")
      display(local_file)

  or in the HTML notebook, just:

      FileLink("my/data.txt")

  `__init__`(path, url_prefix='', result_html_prefix='', result_html_suffix='<br>')

    Parameters: | path : str path to the file or directory that should be formatted directory_prefix : str prefix to be prepended to all files to form a working link [default: ‘files’] result_html_prefix : str text to append to beginning to link [default: none] result_html_suffix : str text to append at the end of link [default: ‘<br>’]

class `IPython.display.` `FileLinks`(path, url_prefix='', included_suffixes=None, result_html_prefix='', result_html_suffix='<br>', notebook_display_formatter=None, terminal_display_formatter=None, recursive=True)

  Bases: `IPython.lib.display.FileLink`

  Class for embedding local file links in an IPython session, based on path

  e.g. to embed links to files that were generated in the IPython notebook under `my/data`, you would do:

      local_files = FileLinks("my/data")
      display(local_files)

  or in the HTML notebook, just:

      FileLinks("my/data")

  `__init__`(path, url_prefix='', included_suffixes=None, result_html_prefix='', result_html_suffix='<br>', notebook_display_formatter=None, terminal_display_formatter=None, recursive=True)

    See `FileLink` for the `path`, `url_prefix`, `result_html_prefix` and `result_html_suffix` parameters.

    included_suffixes
    : list
      Filename suffixes to include when formatting output [default: include all files]
    notebook_display_formatter
    : function
      Used to format links for display in the notebook. See discussion of formatter functions below.
    terminal_display_formatter
    : function
      Used to format links for display in the terminal. See discussion of formatter functions below.

    Formatter functions must be of the form:

        f(dirname, fnames, included_suffixes)

    dirname
    : str
      The name of a directory
    fnames
    : list
      The files in that directory
    included_suffixes
    : list
      The file suffixes that should be included in the output (passing None meansto include all suffixes in the output in the built-in formatters)
    recursive
    : boolean
      Whether to recurse into subdirectories. Default is True.

    The function should return a list of lines that will be printed in the notebook (if passing notebook_display_formatter) or the terminal (if passing terminal_display_formatter). This function is iterated over for each directory in self.path. Default formatters are in place, can be passed here to support alternative formatting.

class `IPython.display.` `HTML`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.TextDisplayObject`

class `IPython.display.` `IFrame`(src, width, height, **kwargs)

  Bases: `object`

  Generic class to embed an iframe in an IPython notebook

  `__init__`(src, width, height, **kwargs)

class `IPython.display.` `Image`(data=None, url=None, filename=None, format=u'png', embed=None, width=None, height=None, retina=False, unconfined=False, metadata=None)

  Bases: `IPython.core.display.DisplayObject`

  `__init__`(data=None, url=None, filename=None, format=u'png', embed=None, width=None, height=None, retina=False, unconfined=False, metadata=None)

    Create a PNG/JPEG 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). 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 to which to constrain the image in html height : int Height 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‘)

  `reload`()

    Reload the raw data from file or URL.

class `IPython.display.` `JSON`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.DisplayObject`

  JSON expects a JSON-able dict or list

  not an already-serialized JSON string.

  Scalar types (None, number, string) are not allowed, only dict or list containers.

class `IPython.display.` `Javascript`(data=None, url=None, filename=None, lib=None, css=None)

  Bases: `IPython.core.display.TextDisplayObject`

  `__init__`(data=None, url=None, filename=None, lib=None, css=None)

    Create a Javascript display object given raw data.

    When this object is returned by an expression or passed to the display function, it will result in the data being displayed in the frontend. If the data is a URL, the data will first be downloaded and then displayed.

    In the Notebook, the containing element will be available as `element`, and jQuery will be available. Content appended to `element` will be visible in the output area.

    Parameters: | data : unicode, str or bytes The Javascript source code or a URL to download it from. url : unicode A URL to download the data from. filename : unicode Path to a local file to load the data from. lib : list or str A sequence of Javascript library URLs to load asynchronously before running the source code. The full URLs of the libraries should be given. A single Javascript library URL can also be given as a string. css: : list or str A sequence of css files to load before running the source code. The full URLs of the css files should be given. A single css URL can also be given as a string.

class `IPython.display.` `Latex`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.TextDisplayObject`

class `IPython.display.` `Markdown`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.TextDisplayObject`

class `IPython.display.` `Math`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.TextDisplayObject`

class `IPython.display.` `Pretty`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.TextDisplayObject`

class `IPython.display.` `SVG`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.DisplayObject`

class `IPython.display.` `ScribdDocument`(id, width=400, height=300, **kwargs)

  Bases: `IPython.lib.display.IFrame`

  Class for embedding a Scribd document in an IPython session

  Use the start_page params to specify a starting point in the document Use the view_mode params to specify display type one off scroll | slideshow | book

  e.g to Display Wes’ foundational paper about PANDAS in book mode from page 3

  ScribdDocument(71048089, width=800, height=400, start_page=3, view_mode=”book”)

  `__init__`(id, width=400, height=300, **kwargs)

class `IPython.display.` `TextDisplayObject`(data=None, url=None, filename=None)

  Bases: `IPython.core.display.DisplayObject`

  Validate that display data is text

class `IPython.display.` `VimeoVideo`(id, width=400, height=300, **kwargs)

  Bases: `IPython.lib.display.IFrame`

  Class for embedding a Vimeo video in an IPython session, based on its video id.

  `__init__`(id, width=400, height=300, **kwargs)

class `IPython.display.` `YouTubeVideo`(id, width=400, height=300, **kwargs)

  Bases: `IPython.lib.display.IFrame`

  Class for embedding a YouTube Video in an IPython session, based on its video id.

  e.g. to embed the video from https://www.youtube.com/watch?v=foo , you would do:

      vid = YouTubeVideo("foo")
      display(vid)

  To start from 30 seconds:

      vid = YouTubeVideo("abc", start=30)
      display(vid)

  To calculate seconds from time as hours, minutes, seconds use `datetime.timedelta`:

      start=int(timedelta(hours=1, minutes=46, seconds=40).total_seconds())

  Other parameters can be provided as documented at https://developers.google.com/youtube/player_parameters#parameter-subheader

  `__init__`(id, width=400, height=300, **kwargs)

## 15 Functions

`IPython.display.` `clear_output`(wait=False)

  Clear the output of the current cell receiving output.

  Parameters: | wait : bool [default: false] Wait to clear the output until new output is available to replace it.

`IPython.display.` `display`(*objs, **kwargs)

  Display a Python object in all frontends.

  By default all representations will be computed and sent to the frontends. Frontends can decide which representation is used and how.

  Parameters: | objs : tuple of objects The Python objects to display. raw : bool, optional Are the objects to be displayed already mimetype-keyed dicts of raw display data, or Python objects that need to be formatted before display? [default: False] include : list or tuple, optional A list of format type strings (MIME types) to include in the format data dict. If this is set only the format types included in this list will be computed. exclude : list or tuple, optional A list of format type strings (MIME types) to exclude in the format data dict. If this is set all format types will be computed, except for those included in this argument. metadata : dict, optional A dictionary of metadata to associate with the output. mime-type keys in this dictionary will be associated with the individual representation formats, if they exist.

`IPython.display.` `display_html`(*objs, **kwargs)

  Display the HTML representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw HTML data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_javascript`(*objs, **kwargs)

  Display the Javascript representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw javascript data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_jpeg`(*objs, **kwargs)

  Display the JPEG representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw JPEG data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_json`(*objs, **kwargs)

  Display the JSON representation of an object.

  Note that not many frontends support displaying JSON.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw json data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_latex`(*objs, **kwargs)

  Display the LaTeX representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw latex data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_markdown`(*objs, **kwargs)

  Displays the Markdown representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw markdown data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_pdf`(*objs, **kwargs)

  Display the PDF representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw javascript data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_png`(*objs, **kwargs)

  Display the PNG representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw png data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_pretty`(*objs, **kwargs)

  Display the pretty (default) representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw text data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `display_svg`(*objs, **kwargs)

  Display the SVG representation of an object.

  Parameters: | objs : tuple of objects The Python objects to display, or if raw=True raw svg data to display. raw : bool Are the data objects raw data or Python objects that need to be formatted before display? [default: False] metadata : dict (optional) Metadata to be associated with the specific mimetype output.

`IPython.display.` `publish_display_data`(data, metadata=None, source=None)

  Publish data and metadata to all frontends.

  See the `display_data` message in the messaging documentation for more details about this message type.

  The following MIME types are currently implemented:

  - text/plain
  - text/html
  - text/markdown
  - text/latex
  - application/json
  - application/javascript
  - image/png
  - image/jpeg
  - image/svg+xml

  Parameters: | data : dict A dictionary having keys that are valid MIME types (like ‘text/plain’ or ‘image/svg+xml’) and values that are the data for that MIME type. The data itself must be a JSON’able data structure. Minimally all data should have the ‘text/plain’ data, which can be displayed by all frontends. If more than the plain text is given, it is up to the frontend to decide which representation to use. metadata : dict A dictionary for metadata related to the data. This can contain arbitrary key, value pairs that frontends can use to interpret the data. mime-type keys matching those in data can be used to specify metadata about particular representations. source : str, deprecated Unused.

`IPython.display.` `set_matplotlib_close`(close=True)

  Set whether the inline backend closes all figures automatically or not.

  By default, the inline backend used in the IPython Notebook will close all matplotlib figures automatically after each cell is run. This means that plots in different cells won’t interfere. Sometimes, you may want to make a plot in one cell and then refine it in later cells. This can be accomplished by:

      In [1]: set_matplotlib_close(False)

  To set this in your config files use the following:

      c.InlineBackend.close_figures = False

  Parameters: | close : bool Should all matplotlib figures be automatically closed after each cell is run?

`IPython.display.` `set_matplotlib_formats`(*formats, **kwargs)

  Select figure formats for the inline backend. Optionally pass quality for JPEG.

  For example, this enables PNG and JPEG output with a JPEG quality of 90%:

      In [1]: set_matplotlib_formats('png', 'jpeg', quality=90)

  To set this in your config files use the following:

      c.InlineBackend.figure_formats = {'png', 'jpeg'}
      c.InlineBackend.print_figure_kwargs.update({'quality' : 90})

  Parameters: | *formats : strs One or more figure formats to enable: ‘png’, ‘retina’, ‘jpeg’, ‘svg’, ‘pdf’. **kwargs : Keyword args will be relayed to `figure.canvas.print_figure`.