Plotting example class

class DCPlot(figureTitle: str, xAxisLabel: str, xAxisUnit: str, yAxis: list[dict[str, str]], data: Optional[list[list[float]]] = None, **kwargs)

Example class for plotting the data.

This class is an example to show the data in an exemplary way. For special use cases, everyone must implement the plots themselves. The plot was optimized for data over a time track.

X and Y axis are always displayed linearly. The labeling and unit of the axes can be adjusted separately.

The constructor creates the plotting window with labels without data. Theoretically, an infinite number of y axes are possible. However, only 2 have been tested so far. The axes are automatically formatted with engineering prefixes.

The display blocks as long as it does not get any computing time. It is optimized to be able to append data, and remains open after plt.show(). By default, matplotlib would wait until the display is closed by the user.

Example of how the yAxis parameter must be formatted:

[{“label”: “Voltage”, “unit”: “V”}, {“label”: “Current”, “unit”: “A”, “log”: True}]

The structure is an array with a dictionary for each axis. The dictionary has two keys:

  • label: The label of the axis.

  • unit: The unit of the axis.

Parameters
  • figureTitle – Title of the figure.

  • xAxisLabel – Lable of the X-axis.

  • xAxisUnit – Unit of the X-axis.

  • yAxis – Data structure for the Y-axis.

addData(xData: list[float], yDatas: list[list[float]], redraw: bool = True) None

Append the data of the plot.

This method is used to append data to the plot.

xData contains an array with values for the X-axis. yDatas contains an array with one array for each Y-axis. The number of points must be the same for each data track.

Example structure:

xData = [0,1,2,3] yDatas = [[0,1,2,3],[0,1,2,3],…]

Parameters
  • xData – Array with points for the X-axis.

  • yDatas – Array with arrys for each Y-axis.

pause(time: float) None

Pause the plot.

When the display pause is called, it gets compute time and is re-rendered.

Parameters

time – Pause in seconds.

clearData() None

Clear the data from the plot.

This command only deletes the data from the display.

clearPlot() None

Clear the data from the plot.

This command deletes the data from the display and then redraws all of them to update the display.

savePlot(file: str, w: Optional[float] = None, h: Optional[float] = None) None

Saving the plot.

Saving the plot, where the size of the plot can be adjusted beforehand. When saving, the file type must also be specified in the file name. These are the data types of the corresponding matplotlib command https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html . PDF works well for vector graphics.

Parameters
  • file – File to save, with path and filetype.

  • w – With of the image in inches, but can be omitted if not needed.

  • h – Height of the image in inches, but can be omitted if not needed. If only w is set, w is also used for the height, by matplotlib and the image is square.

close() None

Close the plot.

isOpen() bool

Check if the window is open.

Checks if the window is still open. If the window is closed, a private variable in the callback is set to false.

Returns

True if the window is open else False.

_closeEvent(evt) None

Close event.

This function is called when the plotting window is closed.