streamsim.src.renderers.vline module
Matplotlib Streaming Renderer with Change Point Visualization by usage of vertical lines.
This module provides a streaming renderer class for visualizing time-series data with automatic annotation of detected change points (anomalies). It is designed for integration with real-time data pipelines where change points need to be highlighted dynamically as new data arrives.
The renderer maintains a sliding time window, automatically removing outdated visual elements and adding new ones for change points within the visible range. This ensures efficient memory usage during long-running streaming sessions.
- Features:
Dynamic title updates with feature values
Automatic cleanup of out-of-window change point markers
Configurable styling for signal lines and change point indicators
- Important Dependencies:
streamsim.src.core.interfaces.StreamingRenderer: Base interface
Author: F.Feenstra
Example
>>> import matplotlib.pyplot as plt
>>> from streamsim.src.renderers.vline import VerticalLineRenderer
>>> renderer = VerticalLineRenderer(
... line_color='black',
... vline_color='red',
... title_template='Heart Rate: {feature:.1f} bpm'
... )
>>> 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.vline.VerticalLineRenderer(line_color: str = 'blue', line_width: float = 2, signal_label: str = 'Signal', vline_color: str = 'red', vline_style: str = '--', vline_width: float = 1.5, vline_alpha: float = 0.7, vline_label: str = 'Anomaly', show_legend: bool = True, title_template: str = 'Streaming Data — Feature: {feature:.4f}')[source]
Bases:
StreamingRendererStreaming renderer that displays vertical lines at detected change points.
This class extends the StreamingRenderer interface to provide real-time visualization of time-series signals with annotated change points. Each change point is marked with a configurable vertical line that persists only while within the visible time window.
The renderer tracks displayed change points internally to prevent duplicate annotations when the same change point is received across multiple update cycles. Out-of-window change points are automatically removed to maintain rendering performance.
- cleanup() None[source]
Release resources and clear references.
Removes all vertical line artists from the axes, clears internal tracking sets, and nullifies references to prevent memory leaks during long-running streaming sessions.
Note
Call this method when the renderer is no longer needed to ensure proper garbage collection of matplotlib artist objects.
- initialize(ax: Any) List[Any][source]
Create initial plot elements on the provided axes.
- Parameters:
ax (Any) – The matplotlib Axes instance to draw on.
- Returns:
List of artist objects for animation tracking.
- Return type:
List[Any]
Example
>>> fig, ax = plt.subplots() >>> renderer = VerticalLineRenderer() >>> 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