API Reference

Simulation control

Control interface

class Control(**kwargs)[source]

Control panel widget for an interactive simulation.

Parameters
  • model – A simulation model with discrete steps.

  • parameters (dict, optional) – Dictionary of parameter names and values (default None). Entries of type Range, IntRange, and Values will be displayed as interactive widgets.

  • variables (str of list of str, optional) – Model attributes to display in the control panel (default None).

Parameter ranges

class Range(vmin=0, vmax=1, vdef=None)[source]

A range of parameter values that can be passed to Control.

Parameters
  • vmin (float, optional) – Minimum value for this parameter (default 0).

  • vmax (float, optional) – Maximum value for this parameter (default 1).

  • vdef (float, optional) – Default value. Default value. If none is passed, vmin is used.

class IntRange(vmin=0, vmax=1, vdef=None)[source]

A range of integer parameter values that can be passed to Control. Similar to Range, but sampled values will be rounded and converted to integer.

Parameters
  • vmin (int, optional) – Minimum value for this parameter (default 0).

  • vmax (int, optional) – Maximum value for this parameter (default 1).

  • vdef (int, optional) – Default value. If none is passed, vmin is used.

class Values(*args, vdef=None)[source]

A pre-defined set of discrete parameter values that can be passed to Control.

Parameters
  • *args – Possible values for this parameter.

  • vdef – Default value. If none is passed, the first passed value is used.

Visualization widgets

Pre-defined plots

class Lineplot(**kwargs)[source]

Chart widget for one or multiple data-series.

Parameters
  • control (Control) – The simulation control panel.

  • y (str or function or list) – Data collector(s) for the y axis.

  • ylabel (str or list of str, optional) – Label(s) for the y axis.

  • x (str, or function, optional) – Data collector for the x axis (default ‘t’).

  • xlabel (str, optional) – Label for the x axis (default ‘Time-step t’).

class Scatterplot(**kwargs)[source]

Chart widget for a scatterplot.

Parameters
  • control (Control) – The simulation control panel.

  • xy (str or function) – Data collector for the x and y coordinates (see Data collectors).

  • c (str or function) – Data collector for the colors (see Data Collector).

Custom widgets

class CustomWidget(**kwargs)[source]

Custom visualization widget.

Parameters
  • control (Control) – The simulation control panel.

  • source (dict of str) –

    Dictionary of strings with javascript functions that define the visualization of the widget. Possible entries are:

    • ’setup’: Called when a new view is rendered.

    • ’update’: Called when new data is synched.

    • ’reset’: Called when the simulation is reset.

    Functions can access the widget view and widget model with view and view.model. The D3 library can be accessed with d3. Collected data is passed to the update function as data.

  • config (dict) – Configuration data that can be accessed by the visualization functions defined in source, using view.model.config.

  • data (dict) – Dictionary of variable names and ref:collectors.

class Matplot(**kwargs)[source]

Matplotlib subplots widget with a custom update function.

Parameters