Plotting¶
VBPCApy provides three convenience plotting functions. They require matplotlib,
installed via the plot extra.
Install¶
Scree plot¶
Shows the explained variance ratio for each component with an optional cumulative line:
from vbpca_py import VBPCA
from vbpca_py.plotting import scree_plot
model = VBPCA(n_components=10, maxiters=200)
model.fit(X)
fig = scree_plot(model, cumulative=True)
Pass an existing axes to embed in a subplot:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
scree_plot(model, ax=ax, cumulative=True)
ax.set_title("My scree plot")
plt.show()
Loadings bar plot¶
Visualise which features contribute most to a given component:
| Parameter | Description |
|---|---|
component |
Zero-indexed component to plot (default: 0) |
top_n |
Show only the N highest-magnitude features |
feature_names |
List of feature name strings for the x-axis |
Variance explained plot¶
Absolute variance (not ratio) per component, useful for comparing across models:
Customisation¶
All three functions return a matplotlib.figure.Figure and accept an optional
ax parameter. Use standard matplotlib API to customise colours, labels,
saving, etc.: