treescope#
Displaying values#
To display individual values using Treescope without configuring it as the default pretty-printer, you can use these functions:
|
Shows a list of objects inline, like python print, but with rich display. |
|
Displays a value as an interactively foldable object. |
|
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:
|
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:
|
Registers treescope as the default IPython renderer. |
Registers the |
|
Registers the |
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:
An automatic visualizer for arrays. |
|
Protocol for autovisualizers. |
|
Used by autovisualizers to replace a subtree with a display object. |
|
Used by autovisualizers to switch to a different autovisualizer. |
|
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 sequential colormap. |
|
The active autovisualizer to use when rendering a tree to HTML. |
|
The default renderer to use when rendering a tree to HTML. |
|
The default autovisualizer to use for the |
|
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.
|
Renders an object to HTML using the default renderer. |
|
Renders an object to text using the default renderer. |
Other utilities#
|
Returns a "digitbox" rendering of a single integer. |
|
Renders the sharding of an array. |
|
Context manager that modifies the expansion strategy of Treescope. |