Skip to content

Add arrow_kwargs and label_kwargs to PCA biplot (fix issue #1311) - #1335

Open
jg585Username wants to merge 2 commits into
DistrictDataLabs:developfrom
jg585Username:feature/pca-biplot-arrow-kwargs
Open

Add arrow_kwargs and label_kwargs to PCA biplot (fix issue #1311)#1335
jg585Username wants to merge 2 commits into
DistrictDataLabs:developfrom
jg585Username:feature/pca-biplot-arrow-kwargs

Conversation

@jg585Username

Copy link
Copy Markdown

Summary

Closes #1311

The PCA biplot (proj_features=True) hardcodes color="r" (red) for
arrows and labels in _draw_projection_features, with no way to override it.
This causes visual ambiguity when the default class color palette also uses red
(e.g. class 2 in the iris dataset).

Changes

  • Added arrow_kwargs parameter to PCA.__init__ and pca_decomposition()
    a dict passed to ax.arrow() (2D) or ax.plot() (3D) for arrow styling
  • Added label_kwargs parameter — a dict passed to ax.text() for label styling
  • Defaults preserve existing behavior (color="r") so this is fully backwards compatible

Before — no way to change arrow color

viz = PCADecomposition(scale=True, proj_features=True)

After — full control over arrow and label appearance

viz = PCADecomposition(
scale=True,
proj_features=True,
arrow_kwargs={"color": "black", "head_width": 0.08},
label_kwargs={"color": "black", "fontsize": 11},
)

Allows users to customize arrow and label colors and other properties
in the PCA biplot via dictionary arguments, instead of being locked
to the hardcoded red color. Closes DistrictDataLabs#1311.
@jg585Username

Copy link
Copy Markdown
Author

Note on Test Failures:

The existing test suite may show ImageComparisonFailure errors. These are
pre-existing issues due to matplotlib rendering changes in newer versions
(fonts, spacing, colors differ from old baseline images) and are not caused
by this change. This update adds new optional parameters that are fully
backwards compatible and do not affect the current, core logic.

- max_z was incorrectly reading Xp[:, 1] (Y column) instead of Xp[:, 2]
- arrow_props with head_width/width are now only set for the 2D path;
  the 3D path uses a separate defaults dict so ax.plot() does not
  receive kwargs it does not accept
@jg585Username jg585Username reopened this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add arguments to change PCA biplot arrow and arrow label colors and other properties

1 participant