IPython Documentation

Table Of Contents

Previous topic

Module: core.debugger

Next topic

Module: core.display_trap

This Page

Module: core.display

Top-level display functions for displaying object in different formats.

Authors:

  • Brian Granger

10 Classes

class IPython.core.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.core.display.TextDisplayObject(data=None, url=None, filename=None)

Bases: IPython.core.display.DisplayObject

Validate that display data is text

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

Bases: IPython.core.display.TextDisplayObject

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

Bases: IPython.core.display.TextDisplayObject

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

Bases: IPython.core.display.TextDisplayObject

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

Bases: IPython.core.display.TextDisplayObject

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

Bases: IPython.core.display.DisplayObject

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

Bases: IPython.core.display.TextDisplayObject

class IPython.core.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. The output area starts hidden, so if the js appends content to element that should be visible, then it must call container.show() to unhide the 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.core.display.Image(data=None, url=None, filename=None, format=u'png', embed=None, width=None, height=None, retina=False)

Bases: IPython.core.display.DisplayObject

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

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.

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.

13 Functions

IPython.core.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.core.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.core.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.core.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.core.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.core.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.core.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.core.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.core.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.core.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.core.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.core.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.

IPython.core.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?