toyplot.html module

toyplot.html.apply_changes(html, changes)[source]
toyplot.html.render(canvas, fobj=None, animation=False)[source]

Render the HTML representation of a canvas.

Generates HTML markup with an embedded SVG representation of the canvas, plus JavaScript code for interactivity. If the canvas contains animation, the markup will include an HTML user interface to control playback.

  • canvas (toyplot.canvas.Canvas) – The canvas to be rendered.
  • fobj (file-like object or string, optional) – The file to write. Use a string filepath to write data directly to disk. If None (the default), the HTML tree will be returned to the caller instead.
  • animation (boolean, optional) – If True, return a representation of the changes to be made to the HTML tree for animation.

  • html (xml.etree.ElementTree.Element or None) – HTML representation of canvas, as a DOM tree, or None if the caller specifies the fobj parameter.
  • changes (JSON-compatible data structure, or None) – JSON-compatible representation of the animated changes to canvas.


The output HTML is the “canonical” representation of a Toyplot canvas - the other toyplot backends operate by converting the output from toyplot.html.render() to the desired end target.

Note that the output HTML is a fragment wrapped in a <div>, suitable for embedding in a larger document. It is the caller’s responsibility to supply the <html>, <body> etc. if the result is intended as a standalone HTML document.