poulet_py.utils.oscilloscope module#

class Oscilloscope(max_samples=1000, max_points=100, title='Real-time Data', xlabel='X', ylabel='Y', xlim='auto', ylim='auto', xpadding=0.1, ypadding=0.1, animation_interval=33)[source]#

Bases: object

A real-time data visualization tool similar to an oscilloscope.

This class provides a thread-safe, animated plotting interface for visualizing streaming data with automatic downsampling and view adjustment.

Parameters:
  • max_samples (int, optional) – Maximum number of samples to keep in memory (default: 1000).

  • max_points (int, optional) – Maximum number of points to display (downsampling threshold, default: 100).

  • title (str, optional) – Title of the plot (default: “Real-time Data”).

  • xlabel (str, optional) – Label for the x-axis (default: “X”).

  • ylabel (str, optional) – Label for the y-axis (default: “Y”).

  • xlim (tuple[float, float] or "auto", optional) – Fixed x-axis limits or “auto” for automatic adjustment (default: “auto”).

  • ylim (tuple[float, float] or "auto", optional) – Fixed y-axis limits or “auto” for automatic adjustment (default: “auto”).

  • xpadding (float, optional) – Padding factor for x-axis when in auto mode (default: 0.1).

  • ypadding (float, optional) – Padding factor for y-axis when in auto mode (default: 0.1).

  • animation_interval (int, optional) – Refresh interval in milliseconds (default: 33 ~30fps).

fig#

The figure instance containing the plot.

Type:

matplotlib.figure.Figure

ax#

The axes instance for the plot.

Type:

matplotlib.axes.Axes

Examples

>>> osc = Oscilloscope(max_samples=500, title="Sensor Data")
>>> osc.start()
>>> osc.add_data({"temp": 25.3, "humidity": 45.2})
__init__(max_samples=1000, max_points=100, title='Real-time Data', xlabel='X', ylabel='Y', xlim='auto', ylim='auto', xpadding=0.1, ypadding=0.1, animation_interval=33)[source]#
add_data(y, x=None)[source]#

Add new data points to the oscilloscope.

This method is thread-safe and can be called from multiple threads.

Parameters:
  • y (dict) – Dictionary of y-values where keys are series names and values are the data points. Each call adds one sample per series.

  • x (Any, optional) – Corresponding x-value for the y samples. If None, uses an auto-incremented index (default: None).

Return type:

None

Notes

The data is stored in internal buffers and will be displayed during the next animation frame.

start()[source]#

Start the real-time plotting animation.

Enables interactive mode and begins periodic updates of the display. The plot window will be non-blocking.

See also

stop

Stop the animation and close the window.

Return type:

None

stop()[source]#

Stop the animation and clean up resources.

Closes the plot window and clears all internal data buffers.

Return type:

None

force_redraw()[source]#

Force an immediate redraw of the plot.

Useful when you need to update the display outside the normal animation interval.

Return type:

None