fix(labels): separate per-render categorical legends with distinct palettes#723
Open
timtreis wants to merge 2 commits into
Open
fix(labels): separate per-render categorical legends with distinct palettes#723timtreis wants to merge 2 commits into
timtreis wants to merge 2 commits into
Conversation
132b23f to
01120e5
Compare
…lettes (#364) Stacking multiple categorical `render_labels` calls produced a single merged legend (scanpy's bare `ax.legend()` auto-collected every labeled artist and dropped the previous legend) and reused the same default palette, so the overlaid layers were indistinguishable. - Each categorical render now gets its own legend; 2nd+ legends are built with explicit handles and laid out left-to-right along the top margin in a post-render pass (`_layout_panel_legends_rightward`), robust to tall legends and `constrained_layout` reflow. Only legends this code owns (tagged `_sdata_column`) are touched, so fill/outline and channel legends keep their placement. - Later categorical label renders offset into the palette to skip colors already used on the panel (`_next_palette_colors`), keeping layers distinct. - A legend is titled by its column only when 2+ legends share an axis (to tell them apart); a lone legend stays untitled. - Shared helpers `_legend_ncol`, `_categorical_legend_handles`, and `_default_categorical_palette` remove duplicated logic. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #723 +/- ##
==========================================
+ Coverage 79.09% 79.14% +0.05%
==========================================
Files 17 17
Lines 4467 4532 +65
Branches 999 1015 +16
==========================================
+ Hits 3533 3587 +54
- Misses 593 595 +2
- Partials 341 350 +9
🚀 New features to boost your workflow:
|
…tically The per-render categorical legends (#364) were laid left-to-right in figure fraction with no width budget, so a 2nd legend overflowed the figure's right edge (clipped, or rescued by bbox_inches=tight into a wide gap). Stack them top-to-bottom in the right margin instead — the standard right-margin convention — so wide legends grow figure height on save rather than running off the right. Also title a lone categorical legend by its source column (it previously went through scanpy's untitled right-margin path), matching the colorbar auto-title and the 2+-legend behavior.
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.
Fixes #364.
Stacking categorical
render_labelscalls gave one merged legend (scanpy's bareax.legend()collected every artist and dropped the prior legend) with reused colors._sdata_column, so fill/outline & channel legends are untouched).