Reference 〉Class
BaseVisualization
MPLVisualization

TimeSeries( Helipad model )

The TimeSeries class is a Matplotlib-based visualizer for displaying time series data on plots so the whole history of any given variable over the model’s runtime can be seen at once.

This class should not be initialized by user code. Rather, import the class and use model.useVisual(TimeSeries).

Features

  • Plots automatically rescale with new data
  • Series registered with an AgentReporter created with the std or percentiles arguments will display intervals alongside the main series.
  • In addition to the normal display, series can also be stacked vertically within a plot
  • Creates a checkgrid parameter ‘plots’ where the various registered plots can be toggled on and off before runtime
  • Legend boxes in the top-right corner can be toggled by pressing ‘t’
  • The plot underneath the mouse cursor can be toggled between log and linear scale by pressing ‘l’
  • Individual lines can be toggled on and off in a particular plot by clicking the name of the line in the legend box.
  • Automatically adjusts resolution downward at t=2,500, 25,000, etc. in order to remain performant

Initialization Parameters

  • model Helipad, required

    The model object.

Methods

Click a method name for more detailed documentation.

  • addKeypress( key, fn )

    Registers a function to be run when a key is pressed in a Matplotlib visualizer.

  • addPlot( name, label, position, … )

    Registers a plot area in the TimeSeries plot area to which data series can be added.

  • removePlot( name, reassign )

    Removes a plot or plots and optionally reassigns their series to a different plot. This function can only be run prior to model.launchCpanel().

  • catchKeypress( event )

    The callback function that sends keypresses to functions defined in MPLVisualization.addKeypress(). This function should not be called directly by user code unless to simulate a keypress.

  • event( t, color, linestyle, … )

    Draws a vertical line on the plots area at time t. This function should not be called directly; specify an event instead.

  • launch( title )

    Launches the visualization window (if in Tkinter) or cell (if in Jupyter). This method is required to be implemented by subclasses, which should call super().launch(title) after creating the Matplotlib figure object.

  • terminate( )

    Cleanup on model termination. This function is called automatically from model.terminate() and should not be called from user code.

  • toggleLine( event )

    Toggles a series on or off. This function is called when a series name is clicked in the legend of a plot.

  • update( data )

    Updates the visualization with new data and refreshes the display. This is mandatory for any subclasses to implement. Subclasses implementing this method should also use it to store any data necessary for future visualizer operations.

    This function should only rarely be called by the user; call model.step() instead to increment the model by one period and update the graph.

Properties

  • isNull bool

    True when the model should run as-if with no visualization, for example if all the plots are unselected. False indicates the window can be launched.

  • lastUpdate int

    Because the model can be set to refresh the visualization only every so many periods, this property records the model time when data was last drawn to the visualization.

    Initial value: 0

  • fig matplotlib.Figure

    The Matplotlib Figure object used for rendering the visualization as a whole.

  • plots dict{str:Plot}

    A dict of registered Plot objects.

  • activePlots dict{str:Plot}

    A dynamic property consisting of the subset of the plots containing the Plots that are currently active.

  • keys dict{str: list[func]}

    Where functions defined in MPLVisualization.addKeypress() are stored.

    Initial value: {}

  • resolution int

    The time elapsing between any two data points drawn to screen (not the time elapsing between two updates, which is a user-controlled parameter). resolution increases by 10× at period 2,500, 25,000, 250,000, etc.

    Initial value: 1

Hooks

Click a hook name for more detailed documentation.

  • visualRefresh( model, visual )

    Runs when the visualizer updates, every n periods as determined by the refresh parameter.

  • visualLaunch( model, visual )

    Runs when model.launchVisual() is called, after the visualization is launched. Use the modelPostSetup hook to catch before the visualization is launched.

Notes and Examples

  1. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History