LivePlotter Class

class automationshield.plotting.LivePlotter(shield: BaseShield, show_dt: bool = True, show_ref: bool = True, show_pot: bool = False, hold: bool = False)[source]

Bases: Plotter

This class can be used to plot during an experiment. Create an instance of LivePlotter and pass it to your controller’s run() method with the live_plotter keyword argument:

Example:

>>> shield = AeroShield()
>>> plotter = LivePlotter(shield=shield, hold=True)
>>> results = MyController(shield).run(freq=200, cycles=1000, live_plotter=plotter)

This will show a plot that will update during the experiment.

LivePlotter inherits from Plotter and looks mostly identical. However, in order to keep the update loop as fast as possible, The plot limits are set beforehand, based on the run time and bounds of the shield that is being used.

LivePlotter takes the same arguments as Plotter in addition to some extra parameters.

The shield parameter is not optional for a LivePlotter instance. A shield instance is required to set the plot limits.

Parameters:
  • hold (bool, optional) – Whether to keep showing the plot when the experiment is finished, defaults to False. If True, a call to matplotlib.pyplot.show() will block until the window is closed manually. If used in a Jupyter environment, hold must be set to False. Otherwise, the plot window will stop responding, causing the Jupyter kernel to crash.

  • shield (BaseShield)

  • show_dt (bool)

  • show_ref (bool)

  • show_pot (bool)

default_refresh_interval = 0.016666666666666666

Default refresh interval of the plot window in seconds.

setup_figure(shield: BaseShield) tuple[Figure, ndarray[Any, dtype[Axes]]][source]

Create empty figure with axes. Add labels, titles, grids, …

Parameters:

shield (BaseShield) – Shield instance.

Returns:

Figure and (array of) axes.

Return type:

tuple[plt.Figure, np.ndarray[Any, np.dtype[plt.Axes]]]

setup_artists(shield: BaseShield) tuple[dict[str, Line2D], list[Artist]][source]

Add lines to plot data for later. Add legends and text. Anything that should be updated/moved or redrawn each loop should be defined here. Anything that should be updated should be added to a dictionary with a key of your choice. Artists that should only be moved/redrawn should be added to a list.

Parameters:

shield (BaseShield) – Shield instance.

Returns:

dictionary of artists that should be updated and list of artists that only need to be redrawn.

Return type:

tuple[dict[str, plt.Line2D], list[plt.Artist]]

set_plot_limits_time(max_time: int | float, freq: int | float)[source]

Set the x-limits on the input and output plots and the x- and y-limits on the dt plot, if shown. Set the refresh rate of the live plotter: minimum of 60Hz and experiment frequency.

Parameters:
  • max_time (int | float) – Experiment duration.

  • freq (int | float) – Experiment frequency.

close()[source]

Close the plot window. Used when receiving a KeyboardInterrupt.

plot(data: ndarray[tuple[int, ...], dtype[float64]], cntr: c_ulong)[source]

Show live plot and update with experiment data as it is received.

Parameters:
  • data (npt.NDArray[np.float64]) – Experiment data array.

  • cntr (ctypes.c_ulong) – Cycle counter of the experiment.