treescope#

Displaying values#

To display individual values using Treescope without configuring it as the default pretty-printer, you can use these functions:

show(*args[, wrap, space_separated, ...])

Shows a list of objects inline, like python print, but with rich display.

display(value[, ignore_exceptions, ...])

Displays a value as an interactively foldable object.

render_array(array, *[, columns, rows, ...])

Renders an array (positional or named) to a displayable HTML object.

Using Treescope as the default renderer#

To enable Treescope as the default renderer in IPython, you can use:

basic_interactive_setup([autovisualize_arrays])

Sets up IPython for interactive use with Treescope.

This will configure Treescope as the default renderer of all IPython cell outputs. It will also turn on automatic array visualization, enable interactive customization of configuration options, and install the %%autovisualize and %%with IPython magics.

For more control, you can configure these individually:

register_as_default([streaming, compress_html])

Registers treescope as the default IPython renderer.

register_autovisualize_magic()

Registers the %%autovisualize magic.

register_context_manager_magic()

Registers the %%with magic.

Automatic visualization#

Treescope supports automatic visualization of particular leaves of a tree using an “autovisualizer”. The most common autovisualizer is the array autovizualizer, but you can also define your own autovisualizers using any IPython rich display object. (See the custom visualization guide for details.)

To enable an autovisualizer for all Treescope outputs, you can use

treescope.active_autovisualizer.set_globally(
    treescope.ArrayAutovisualizer()  # or your own autovisualizer
)

To enable it for a single display call, you can pass the autovisualize argument to treescope.display or treescope.show, e.g.

treescope.display(..., autovisualize=True)

Alternatively you can use the %%autovisualize magic to turn on automatic visualization in a single cell, e.g.

%%autovisualize treescope.ArrayAutovisualizer()
treescope.display(...)

or just

%%autovisualize
# ^ with no arguments, uses the default array autovisualizer
treescope.display(...)

Types for building autovisualizers:

ArrayAutovisualizer

An automatic visualizer for arrays.

Autovisualizer

Protocol for autovisualizers.

IPythonVisualization

Used by autovisualizers to replace a subtree with a display object.

ChildAutovisualizer

Used by autovisualizers to switch to a different autovisualizer.

VisualizationFromTreescopePart

Used by advanced autovisualizers to directly insert Treescope content.

Configuring rendering options#

Most of Treescope’s rendering options are of type context.ContextualValue. These can be set temporarily using context.ContextualValue.set_scoped, or configured globally using context.ContextualValue.set_globally.

default_diverging_colormap

Default diverging colormap.

default_sequential_colormap

Default sequential colormap.

active_autovisualizer

The active autovisualizer to use when rendering a tree to HTML.

active_renderer

The default renderer to use when rendering a tree to HTML.

default_magic_autovisualizer

The default autovisualizer to use for the %%autovisualize magic.

active_expansion_strategy

The default expansion strategy to use when rendering a tree to HTML.

Rendering to strings#

Instead of displaying objects directly, you can render them to strings to save or display later.

render_to_html(value[, roundtrip_mode, ...])

Renders an object to HTML using the default renderer.

render_to_text(value[, roundtrip_mode, ...])

Renders an object to text using the default renderer.

Other utilities#

integer_digitbox(value, *[, label, size])

Returns a "digitbox" rendering of a single integer.

render_array_sharding(array[, rows, columns])

Renders the sharding of an array.

using_expansion_strategy([max_height, ...])

Context manager that modifies the expansion strategy of Treescope.