Repository navigation
Fix Express legend groups with duplicate labels - #5855
Open
Alex-ardashev wants to merge 1 commit into
Open
Alex-ardashev wants to merge 1 commit into
Alex-ardashev wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Link to issue
Related to #2562: this fixes the legend case described in the issue discussion. The separate hover-label collision remains outside this patch.
Description of change
When different grouping columns share a display label, Plotly Express overwrites one column in the legend-name mapping. This drops group values from trace names, hides legend entries, and gives distinct groups the same legend control. Key the mapping by the source column and apply display labels when building the legend title.
Demo
Before:
[('one', True), ('two', True), ('one', False), ('two', False)]After:
[('A, one', True), ('A, two', True), ('B, one', True), ('B, two', True)]The exported PNG was also checked: it shows all four legend entries with their correct colors and symbols.
Testing strategy
Ten regression cases fail before the fix and pass after it, across pandas (including nullable and Arrow-backed columns), Polars, and PyArrow. Five control cases keep a single legend dimension when color and symbol use the same source column.
pytest tests/test_optional/test_px/test_px.py tests/test_optional/test_px/test_facets.py tests/test_optional/test_px/test_px_hover.py tests/test_optional/test_px/test_marginals.py -q: 540 passed. Ruff lint and formatting pass on both changed Python files. The repository-wide Ruff check reports 1,911 findings, all in unchanged files.Additional information (optional)
Prepared and tested with OpenAI Codex (GPT-6) at Alex-ardashev's request.
Guidelines