Add arrow_kwargs and label_kwargs to PCA biplot (fix issue #1311) - #1335
Open
jg585Username wants to merge 2 commits into
Open
Add arrow_kwargs and label_kwargs to PCA biplot (fix issue #1311)#1335jg585Username wants to merge 2 commits into
jg585Username wants to merge 2 commits into
Conversation
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.
Author
|
Note on Test Failures: The existing test suite may show ImageComparisonFailure errors. These are |
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1311
The PCA biplot (
proj_features=True) hardcodescolor="r"(red) forarrows 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
arrow_kwargsparameter toPCA.__init__andpca_decomposition()—a dict passed to
ax.arrow()(2D) orax.plot()(3D) for arrow stylinglabel_kwargsparameter — a dict passed toax.text()for label stylingcolor="r") so this is fully backwards compatibleBefore — 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},
)