Visualizations & Plotting
The stride.plotting subpackage provides headless visualization functions for data streams, class distributions, and feature manifolds.
Overview
All visualization utilities generate and return matplotlib.figure.Figure instances without invoking plt.show(). This guarantees non-blocking execution across headless CI servers, automated scripts, and Streamlit dashboard containers (st.pyplot(fig)).
from stride.plotting import (
visualize_data_stream,
plot_class_distribution,
plot_feature_space,
plot_feature_target_relationship,
plot_class_share_over_time,
plot_feature_over_time,
)
Key Components
| Function | Return Type | Description |
|---|---|---|
visualize_data_stream |
Figure |
Multi-panel stream trajectory overview plotting feature values and target labels across the time index. |
plot_class_distribution |
Figure |
Class balance evolution chart displaying categorical target proportions across sliding windows. |
plot_feature_space |
Figure |
2D scatter visualization of feature coordinates color-coded by class labels. |
plot_feature_target_relationship |
Figure |
Density and violin plots visualizing feature-target relationships pre- and post-drift. |
plot_class_share_over_time |
Figure |
Stacked area chart of the class shares along the whole stream, with known change points marked. |
plot_feature_over_time |
Figure |
Class-wise mean of one feature along the whole stream (one panel per class) with the mean of every segment between change points. |
API Specification
stride.plotting
Data stream and feature distribution plotting utilities.
plot_class_distribution
plot_class_distribution(
class_dist_before,
class_dist_after,
class_colors,
title="Class Distribution",
)
Create a figure showing class distribution before and after a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_dist_before
|
|
required | |
class_dist_after
|
|
required | |
class_colors
|
Mapping |
required | |
title
|
Figure title. |
'Class Distribution'
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated Matplotlib Figure. |
Source code in src/stride/plotting/stream.py
plot_class_share_over_time
plot_class_share_over_time(
y,
change_points=None,
n_bins=100,
class_colors=None,
segment_labels=None,
title="Class share along the stream",
legend=True,
ax=None,
)
Plot the class proportions along a stream as a stacked area chart.
The stream is cut into n_bins consecutive bins of equal length and the share of
every class is computed per bin. It shows prior drift \(P(Y)\), classes that arrive
in bursts and periods in which a class is absent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Sequence | ndarray | Series
|
Class labels in stream order. |
required |
change_points
|
Sequence[int] | None
|
Positions (row indices) of known changes, drawn as vertical rules. |
None
|
n_bins
|
int
|
Number of consecutive bins the stream is cut into. |
100
|
class_colors
|
Mapping | None
|
Mapping |
None
|
segment_labels
|
Sequence[str] | None
|
Names of the segments between the change points, written above the axes. Requires one name more than there are change points. |
None
|
title
|
str | None
|
Axes title. |
'Class share along the stream'
|
legend
|
bool
|
Whether to draw the class legend below the axes. |
True
|
ax
|
Axes | None
|
Axes to draw on; a new figure is created when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The Matplotlib Figure holding the chart. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of |
Source code in src/stride/plotting/stream.py
plot_feature_over_time
plot_feature_over_time(
values,
y,
change_points=None,
n_bins=100,
min_count=15,
class_colors=None,
segment_labels=None,
title=None,
figsize=None,
)
Plot the class-wise mean of one feature along a stream, one panel per class.
The stream is cut into n_bins consecutive bins; the coloured line is the mean of
the feature per bin and class, and the black segments are the class-wise mean of
every segment between two change points. A level shift at a change point is drift
of \(P(X \mid Y)\); movement inside a segment is drift that was not annotated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence | ndarray | Series
|
Values of one feature in stream order. The name of a Series is used as the feature name. |
required |
y
|
Sequence | ndarray | Series
|
Class labels in stream order. |
required |
change_points
|
Sequence[int] | None
|
Positions (row indices) of known changes, drawn as vertical rules. |
None
|
n_bins
|
int
|
Number of consecutive bins the stream is cut into. |
100
|
min_count
|
int
|
Bins with fewer samples of a class are left out of the line of that class. |
15
|
class_colors
|
Mapping | None
|
Mapping |
None
|
segment_labels
|
Sequence[str] | None
|
Names of the segments between the change points, written above the first panel. |
None
|
title
|
str | None
|
Figure title; by default it names the feature. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size; by default 12 inches wide and 1.4 inches per class. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The Matplotlib Figure with one panel per class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/stride/plotting/stream.py
plot_feature_space
plot_feature_space(
n_features,
feature_names,
X_before,
X_after,
y_before,
y_after,
class_colors,
title="Feature Space",
)
Create a figure showing the feature space for two windows (1D, 2D, or PCA).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_features
|
Number of features. |
required | |
feature_names
|
Feature names. |
required | |
X_before
|
Feature matrix for the before window. |
required | |
X_after
|
Feature matrix for the after window. |
required | |
y_before
|
Class labels for the before window. |
required | |
y_after
|
Class labels for the after window. |
required | |
class_colors
|
Mapping |
required | |
title
|
Figure title. |
'Feature Space'
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated Matplotlib Figure. |
Source code in src/stride/plotting/stream.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
plot_feature_target_relationship
plot_feature_target_relationship(
X,
n_features,
feature_names,
X_before,
X_after,
y_before,
y_after,
class_colors,
title="Feature vs Target Relationship",
viz_type="violin",
)
Create a figure showing feature distributions grouped by class and window.
Each subplot corresponds to one feature. Within each subplot, distributions are stacked horizontally — one pair (Before / After) per class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Full feature matrix (used only for shape information). |
required | |
n_features
|
Number of features. |
required | |
feature_names
|
Feature names. |
required | |
X_before
|
Feature matrix for the before window. |
required | |
X_after
|
Feature matrix for the after window. |
required | |
y_before
|
Class labels for the before window. |
required | |
y_after
|
Class labels for the after window. |
required | |
class_colors
|
Mapping |
required | |
title
|
Figure title. |
'Feature vs Target Relationship'
|
|
viz_type
|
Distribution plot type ("violin", "box", or "scatter"). |
'violin'
|
Returns:
| Type | Description |
|---|---|
Figure
|
The generated Matplotlib Figure. |
Source code in src/stride/plotting/stream.py
visualize_data_stream
visualize_data_stream(
X,
y,
window_before_start,
window_after_start,
window_length,
feature_names,
title_feat_target="Feature vs Target Relationship",
title_class_dist="Class Distribution",
title_feat_space="Feature Space",
viz_type="violin",
)
Visualize the data stream for two specific windows.
Creates three separate figures:
- Feature-target relationships (violin / box / scatter per feature per class)
- Class distributions (bar chart before vs after)
- Feature space (1D histogram, 2D scatter, or PCA projection)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Full feature matrix. |
required | |
y
|
Class labels. |
required | |
window_before_start
|
Start index (inclusive) of the before window. |
required | |
window_after_start
|
Start index (inclusive) of the after window. |
required | |
window_length
|
Number of samples in each window. |
required | |
feature_names
|
Feature names. |
required | |
title_feat_target
|
Title for the feature-target figure. |
'Feature vs Target Relationship'
|
|
title_class_dist
|
Title for the class-distribution figure. |
'Class Distribution'
|
|
title_feat_space
|
Title for the feature-space figure. |
'Feature Space'
|
|
viz_type
|
Distribution plot type ("violin", "box", or "scatter"). |
'violin'
|
Returns:
| Type | Description |
|---|---|
list[Figure]
|
List of three figures in the order described above. |