qewton.visualization.applications package

Module contents

Submodules

qewton.visualization.applications.base module

Base class of the applications, which show a Figure as a connected output.

class qewton.visualization.applications.base.RenderApplication[source]

Bases: object

Base class for wrapping a Figure in an interactive application: a connected output, in which widgets set the states of controls.

connected

Kinds of control that get a widget (class attribute); the other controls are embedded into the drawn figure.

Type:

tuple of type

Notes

Subclasses set connected and implement renderer_classes() and create().

connected: tuple[type, ...] = ()
classmethod renderer_classes() → tuple[type, ...][source]

The renderers whose figures the application shows.

Returns:

Renderer classes.

Return type:

tuple of type

classmethod create(figure)[source]

Build an application serving figure, with a widget for each connected control.

Parameters:

figure (Figure) – The figure to serve.

Returns:

The application.

Return type:

object

classmethod check_renderer(figure) → None[source]

Fail early if the application cannot show figure.

Parameters:

figure (Figure) – The figure.

Raises:

TypeError – If the figure’s renderer is none of renderer_classes().

classmethod interactive_controls(figure) → list[Control][source]

The controls of figure that get a widget, in widget order.

Parameters:

figure (Figure) – The figure.

Returns:

Its controls of a connected kind.

Return type:

list of Control

classmethod embedded_controls(figure) → list[Control][source]

The controls of figure without a widget, embedded into the drawn figure.

Parameters:

figure (Figure) – The figure.

Returns:

Every other control.

Return type:

list of Control

classmethod update(figure, controls: list[Control], states) → object[source]

Set the states of controls and draw figure with the other controls embedded, as a widget callback does.

Parameters:
  • figure (Figure) – The figure.

  • controls – Its interactive controls.

  • states – One state per control.

Returns:

The redrawn backend figure.

Return type:

object

qewton.visualization.applications.base.require(application: str, *packages: str) → None[source]

Fail early if optional packages of an application are missing.

Parameters:
  • application – Name of the application, for the message.

  • *packages – Importable package names.

Raises:

ImportError – Naming every missing package.

qewton.visualization.applications.dash_app module

Interactive Dash application for a Figure.

class qewton.visualization.applications.dash_app.DashApplication[source]

Bases: RenderApplication

Serves a Figure as a Dash app: a slider per SliderAxis and a dropdown per Selector of the figure are connected, i.e. a callback sets their states and draws the figure again; the other controls are embedded into the drawn figure (a TimeAxis as an animation).

connected: tuple[type, ...] = (<class 'qewton.visualization.axes.SliderAxis'>, <class 'qewton.visualization.axes.Selector'>)
classmethod renderer_classes() → tuple[type, ...][source]

See RenderApplication.renderer_classes.

classmethod create(figure)[source]

Build a Dash app displaying figure.

Parameters:

figure (Figure) – The figure to serve.

Returns:

The application; start it with app.run().

Return type:

dash.Dash

Raises:
  • ImportError – If Dash or Plotly is not installed.

  • TypeError – If the figure is not drawn by a PlotlyRenderer.

static label(control: Control, mathjax: bool)[source]

The label of a control’s widget: its name, with math rendered by MathJax if mathjax.

Parameters:
  • control – The control.

  • mathjax – Whether MathJax renders math.

Returns:

The label.

Return type:

dash component

static widget(control: Control, id: str)[source]

A slider for a SliderAxis, a dropdown for a Selector.

Parameters:
  • control – The control the widget sets.

  • id – Component id.

Returns:

The widget, valued by state index.

Return type:

dash component

qewton.visualization.applications.widget_app module

Interactive notebook application for a Figure, with ipywidgets.

class qewton.visualization.applications.widget_app.WidgetApplication[source]

Bases: RenderApplication

Shows a Figure in a notebook: an interactive Matplotlib canvas (ipympl: zoom, pan, 3D rotation) and a widget per control. A slider sets a SliderAxis, a play button with a slider a TimeAxis, a dropdown a Selector; a change sets the state and redraws the figure in place. Every such control is connected, so nothing is embedded.

Example

>>> WidgetApplication.create(Figure(plot, renderer=MatplotlibRenderer()))
connected: tuple[type, ...] = (<class 'qewton.visualization.axes.SliderAxis'>, <class 'qewton.visualization.axes.TimeAxis'>, <class 'qewton.visualization.axes.Selector'>)
classmethod renderer_classes() → tuple[type, ...][source]

See RenderApplication.renderer_classes.

classmethod create(figure)[source]

Build the widgets displaying figure.

Parameters:

figure (Figure) – The figure to show.

Returns:

The canvas, at the figure’s size in a box

scrolling where it is wider than the output, above one row per control; display it as the last expression of a notebook cell.

Return type:

ipywidgets.VBox

Raises:
  • ImportError – If ipywidgets or ipympl is not installed.

  • TypeError – If the figure is not drawn by a MatplotlibRenderer.

static widget(control: Control) → tuple[source]

The row of widgets setting a control: its name as math, then a slider (with a play button for a TimeAxis) or a dropdown.

Parameters:

control – The control.

Returns:

The row (ipywidgets.HBox) and the widget whose

value is the state.

Return type:

tuple