Karana.KUtils.DataPlotter#
Classes and functions used to stream data to a DashApp.
This module contains classes and functions used to stream data to a DashApp. These are useful for plotting data while a simulation is running. The DashApp is a useful format, as it allows one to view the results from a web browser, and that browser does not have to be on the same machine as the machine generating the data. This is particularly useful when running a simulation on a remote machine without an X session.
Classes#
Holds functions to update the plot data for the DataPlotter. |
|
Use this class to create a DashApp servers up static figures. |
|
Use this class to create a DashApp that you can stream data to. |
Module Contents#
- class Karana.KUtils.DataPlotter.PlotDataDS(/, **data: Any)[source]#
Bases:
Karana.KUtils.DataStruct.DataStructHolds functions to update the plot data for the DataPlotter.
- Parameters:
title (str) – Title of the graph.
x_data_name (str) – The name of the x-axis.
x_data (Callable[[], float]) – The callable used to get the x-axis data.
y_data (dict[str, Callable[[], Vec | float]]) – This dictionary holds the names and callables for a plot. The name will be the name used in the legend. The callable gets the data. If the data is a vector with size greater than 1, then the name will be original name plus an index.
- title: str#
- x_data: Callable[[], float]#
- x_data_name: str#
- y_data: dict[str, Callable[[], Karana.KUtils.Ktyping.Vec | float]]#
- class Karana.KUtils.DataPlotter.DashAppStatic(figs: list[plotly.graph_objects.Figure], title: str = 'DataPlotter', host: str = '0.0.0.0', port: int = 8050)[source]#
Bases:
_DashAppBaseUse this class to create a DashApp servers up static figures.
These figures can be changed manually using the figs property. However, they are not designed to be updated regularly. For that, please use the DashApp class.
- property figs: list[plotly.graph_objects.Figure]#
Figures shown by the DashApp.
- class Karana.KUtils.DataPlotter.DashApp(data: list[PlotDataDS], title: str = 'DataPlotter', host: str = '0.0.0.0', port: int = 8050)[source]#
Bases:
_DashAppBaseUse this class to create a DashApp that you can stream data to.
This class will automatically create empty plots based on the PlotDataDS provided. In addition, it will start a websocket and http server for clients to connect to view the plots. Calling update will update the data of the plots based on the data provided in the PlotDataDS.
- data: list[PlotDataDS] = []#
- update()[source]#
Update the plots.
This updates the figures with the data provided in PlotDataDS. Then, it pings the websocket to trigger an update for all the connected clients.
- addPlot(data: PlotDataDS)[source]#
Add a new plot the window using the associated plot data.
- Parameters:
data (PlotDataDS) – The data associated with updating the plot.