Module: display ¶
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).
- 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.
# 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..)
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
Reload the raw data from file or URL.
class IPython.display. DisplayHandle ( display_id=None ) ¶
A handle on an updatable display
Call .update(obj) to display a new object.
Call .display(obj ) to add a new instance of this display, and update existing instances.
Initialize self. See help(type(self)) for accurate signature.
Make a new display with my id, updating existing instances.
Update existing displays with my id
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
Reload the raw data from file or URL.
class IPython.display. FileLink ( path, url_prefix=», result_html_prefix=», result_html_suffix=’
‘ ) ¶
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
local_file = FileLink("my/data.txt") display(local_file)
or in the HTML notebook, just:
- path (str) – path to the file or directory that should be formatted
- url_prefix (str) – prefix to be prepended to all files to form a working link [default: ‘’]
- result_html_prefix (str) – text to append to beginning to link [default: ‘’]
- result_html_suffix (str) – text to append at the end of link [default: ‘
’]
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:
__init__ ( path, url_prefix=», included_suffixes=None, result_html_prefix=», result_html_suffix=’
‘, 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 ) ¶
Generic class to embed an iframe in an IPython notebook
Initialize self. See help(type(self)) for accurate signature.
class IPython.display. Image ( data=None, url=None, filename=None, format=None, embed=None, width=None, height=None, retina=False, unconfined=False, metadata=None ) ¶
__init__ ( data=None, url=None, filename=None, format=None, 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.
# 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 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 the raw data from file or URL.
class IPython.display. JSON ( data=None, url=None, filename=None ) ¶
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 ) ¶
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.
- data (unicode,strorbytes) – 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 (listorstr) – 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 (: listorstr) – 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. Markdown ( data=None, url=None, filename=None ) ¶
class IPython.display. Math ( data=None, url=None, filename=None ) ¶
class IPython.display. Pretty ( data=None, url=None, filename=None ) ¶
class IPython.display. ProgressBar ( total ) ¶
Progressbar supports displaying a progressbar like element
Creates a new progressbar
Parameters: | total (int) – maximum size of the progressbar |
---|
next ( ) ¶
class IPython.display. SVG ( data=None, url=None, filename=None ) ¶
class IPython.display. ScribdDocument ( id, width=400, height=300, **kwargs ) ¶
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”)
Initialize self. See help(type(self)) for accurate signature.
class IPython.display. TextDisplayObject ( data=None, url=None, filename=None ) ¶
Validate that display data is text
class IPython.display. VimeoVideo ( id, width=400, height=300, **kwargs ) ¶
Class for embedding a Vimeo video in an IPython session, based on its video id.
Initialize self. See help(type(self)) for accurate signature.
class IPython.display. YouTubeVideo ( id, width=400, height=300, **kwargs ) ¶
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)
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())
When converting the notebook using nbconvert, a jpeg representation of the video will be inserted in the document.
Initialize self. See help(type(self)) for accurate signature.
16 Functions¶
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.
In terminal IPython this will be similar to using print() , for use in richer frontends see Jupyter notebook examples with rich display logic.
- 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,tupleorset,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,tupleorset,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.
- transient (dict,optional) – A dictionary of transient data to associate with the output. Data in this dict should not be persisted to files (e.g. notebooks).
- display_id (str,bool optional) – Set an id for the display. This id can be used for updating this display area later via update_display. If given as True , generate a new display_id
- kwargs (additional keyword-args,optional) – Additional keyword-arguments are passed through to the display publisher.
handle – Returns a handle on updatable displays for use with update_display() , if display_id is given. Returns None if no display_id is given (default).
>>> class Json(object): . def __init__(self, json): . self.json = json . def _repr_pretty_(self, pp, cycle): . import json . pp.text(json.dumps(self.json, indent=2)) . def __repr__(self): . return str(self.json) .