streamsim.src.renderers.matplotlib_line module

Matplotlib Streaming Renderer with Marker Point Visualization

This module provides a streaming renderer class for visualizing time-series data with automatic annotation of detected Marker points. It is designed for integration with real-time data pipelines where Marker points need to be highlighted dynamically as new data arrives.

The renderer maintains a sliding time window, automatically filtering data to display only the most recent samples within the configured duration. Marker points are interpolated to match the signal line’s y-values at the detected timestamps.

Features:
  • Dynamic title updates with feature values

  • Configurable styling for signal lines and marker points

  • Efficient incremental updates (no full redraws)

  • Automatic visibility management for marker points

  • Resource cleanup via explicit cleanup() method

Important Dependencies:
  • streamsim.src.core.interfaces.StreamingRenderer: Base interface

Author: F.Feenstra

Example

>>> import matplotlib.pyplot as plt
>>> from streamsim.src.renderers.matplotlib_line import MatplotlibLineRenderer
>>> renderer = MatplotlibLineRenderer(
...     line_color='blue',
...     marker_style='ro',
...     marker_alpha=0.8,
...     show_legend=True,
...     marker_label='Peak',
...     title_template="Sinus Wave Peaks — Latest Value: {feature:.1f}"
... )
>>> fig, ax = plt.subplots()
>>> artists = renderer.initialize(ax)
>>> # In streaming loop:
>>> # updated_artists = renderer.update(times, samples, features, change_points, window_duration)
class streamsim.src.renderers.matplotlib_line.MatplotlibLineRenderer(line_color: str = 'blue', line_width: float = 2, marker_style: str = 'ro', marker_alpha: float = 0.7, signal_label: str = 'Signal', marker_label: str = 'Change', show_legend: bool = True, title_template: str = 'Streaming Data Feature: {feature:.4f}')[source]

Bases: StreamingRenderer

Default matplotlib line chart renderer for streaming data visualization.

This class implements the StreamingRenderer interface to provide real-time visualization of streaming signals with configurable styling and marker point annotation. It supports dynamic title updates based on feature values and flexible legend configuration for both signal and marker elements.

Designed for use with the streaming framework’s data pipeline, this renderer efficiently updates plot elements without redrawing the entire figure, making it suitable for high-frequency data streams.

cleanup() None[source]

Release resources and clear references. This method can be called when the simulation is stopped to clean up any resources and prevent memory leaks.

initialize(ax: Any) List[Any][source]

Create initial plot elements on the provided axes.

Sets up the signal line, markers, and dynamic title on the given matplotlib axes. This method should be called once before the streaming loop begins.

Parameters:

ax (Any) – The matplotlib Axes instance to draw on. Typically obtained from plt.subplots() or fig.add_subplot().

Returns:

List of artist objects [line, marker, title_artist] that

should be tracked for efficient updates (e.g., blitting).

Return type:

List[Any]

Example: >>> renderer = MatplotlibLineRenderer( … line_color=’blue’, … marker_style=’ro’, … marker_alpha=0.8, … show_legend=True, … marker_label=’Peak’, … title_template=”Sinus Wave Peaks — Latest Value: {feature:.1f}” … ) >>> fig, ax = plt.subplots() >>> artists = renderer.initialize(ax)

update(times: ndarray, samples: ndarray, features: ndarray, change_points: ndarray, window_duration_sec: float) List[Any][source]

Update plot elements with new streaming data.

Parameters:
  • times (np.ndarray) – Array of timestamps.

  • samples (np.ndarray) – Array of signal values.

  • features (np.ndarray) – Array of feature values.

  • change_points (np.ndarray) – Array of change point timestamps.

  • window_duration_sec (float) – Visible time window duration.

Returns:

Updated artist objects.

Return type:

List[Any]

Example

>>> updated_artists = renderer.update(times, samples, features, change_points, window_duration