Plotter Class

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

Bases: object

Create matplotlib figure. When an instance is created, an empty figure is built with empty plt.Line2D elements. When calling Plotter.plot() with the results of an experiment (output of automationshield.ShieldController.run()), the data is rendered. The Figure and Axes instances are returned by Plotter.plot(), allowing the user to modify the plots before showing them. matplotlib.pyplot.show() must be called in the main script for the figure to be shown.

The figure created by Plotter contains two or three plots in rows:

  • An output plot. This plot shows the sensor values and, optionally, the reference values.

  • An input plot. This plot show the actuator values and, optionally, the potentiometer values.

  • An optional time step plot. This plot show the step size for each time step in the experiment.

Example:

>>> from matplotlib import pyplot as plt
>>>
>>> shield = AeroShield()
>>> results = MyController(shield).run(freq=200, cycles=1000)
>>> fig, ax = Plotter(shield=shield).plot(results)
>>> plt.show()
Parameters:
  • shield (BaseShield, optional) – shield instance being used, defaults to None. If provided, the PlotInfo class attributes are used to add units to the output plot.

  • show_dt (bool) – Whether to show a third plot with the time steps, defaults to True.

  • show_ref (bool) – Whether to plot the reference as given to the run() method, defaults to True.

  • show_pot (bool) – Whether to plot the potentiometer value, defaults to False.

setup_figure(shield: BaseShield | None = None) tuple[Figure, list[Axes]][source]

Create an empty figure. Creates the plots, defines the layout and sets the titles and axis labels.

Parameters:

shield (BaseShield, optional) – Shield instance whose data will be plotted, defaults to None. If provided, units are set on the output plot.

Returns:

Figure and list of axes.

Return type:

tuple[matplotlib.figure.Figure, list[matplotlib.axes.Axes]]

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

Add artists to the figure. Create matplotlib.lines.Line2D instances for each plot line and add legends were needed. All lines are added to a dictionary, any other artists (legends and other stuff) are added to a list. Both are returned.

Parameters:

shield (BaseShield, optional) – Shield instance whose data will be plotted, defaults to None

Returns:

dictionary of line elements, list of other artists.

Return type:

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

plot(data: ndarray[tuple[int, ...], dtype[float64]]) tuple[Figure, list[Axes]][source]

Set the data on the plots. Rescales the plots with the data added.

Parameters:

data (npt.NDArray[np.float_]) – Results from an automationshield.ShieldController experiment.

Returns:

Figure and axes of the plot.

Return type:

tuple[matplotlib.figure.Figure, list[matplotlib.axes.Axes]]

calculate_plot_lines(data: ndarray[tuple[int, ...], dtype[float64]]) dict[str, tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[float64]]]][source]

Calculate the values that should be plotted.

Parameters:

data (npt.NDArray[np.float64]) – Results array received from ShieldController.

Returns:

Dictionary with tuples containing arrays for \(x\) and \(y\) data. The keys in the dictionary must match the ones you assigned in setup_figure(). Any additional keys in this dictionary are ignored.

Return type:

dict[str, tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]]