Visualization¶
SWIFT provides two main visualization methods, both accessible directly from the SWIFTMonitor instance. All plots return (Figure, Axes) tuples for further customization.
Bucket profile¶
The bucket profile visualizes how a feature's SHAP response and observation density are distributed across buckets — the SHAP response curve is exactly the per-bucket mean SHAP fitted in Normalization.
Basic usage¶
# Reference density only
fig, ax = monitor.plot_buckets("feature_0")
The plot shows:
- Left y-axis: Mean SHAP value per bucket (line + markers) with a shaded band showing mean +/- 2 standard deviations
- Right y-axis: Observation density (fraction of samples in each bucket)
- X-axis: Bucket intervals
- Dashed grey line: SHAP = 0 reference
Comparing distributions¶
Pass X_compare to overlay a second distribution (e.g., monitoring vs. reference):
fig, ax = monitor.plot_buckets(
"feature_0",
X_compare=X_drifted,
labels=("Reference", "Drifted"),
)
Custom density source¶
By default, the density is computed from the reference data used during fit(). Pass X to use a different data source:
# Show monitoring density instead of reference
fig, ax = monitor.plot_buckets("feature_0", X=X_mon)
Natural x-axis¶
For a more interpretable x-axis, use x_axis="natural" to show bucket midpoints on the feature-value scale instead of bucket indices:
fig, ax = monitor.plot_buckets("feature_0", x_axis="natural")
When there are more than 20 buckets, the default mode automatically switches to compact labels (B0, B1, ...) for readability.
SWIFT score plot¶
The SWIFT score plot provides an overview of drift across all features.
Single result¶
fig, ax = monitor.plot_swift_scores(result, threshold=0.01)
Shows:
- Bars: One per feature, colored red (drifted) or blue (not drifted)
- Horizontal lines: SWIFT max, SWIFT mean, and optional threshold
Comparing two results¶
fig, ax = monitor.plot_swift_scores(
result_clean,
result_compare=result_drifted,
labels=("Clean", "Drifted"),
)
Shows grouped side-by-side bars with neutral coloring for direct comparison.
Customization¶
Both methods return matplotlib (Figure, Axes) tuples, so you can customize the plots further:
fig, ax = monitor.plot_swift_scores(result)
ax.set_title("My Custom Title")
ax.set_ylabel("SWIFT Score")
fig.savefig("swift_scores.png", dpi=300, bbox_inches="tight")
Standalone functions¶
The plotting functions are also available as standalone functions for advanced use:
from swift.plotting import plot_bucket_profile, plot_feature_swift_scores
See the Plotting API reference for full details.