Skip to content

feat(plotting): shared axis labels for faceted plots#84

Merged
FBumann merged 1 commit into
mainfrom
feat/shared-facet-axis-labels
Jun 3, 2026
Merged

feat(plotting): shared axis labels for faceted plots#84
FBumann merged 1 commit into
mainfrom
feat/shared-facet-axis-labels

Conversation

@FBumann
Copy link
Copy Markdown
Owner

@FBumann FBumann commented Jun 3, 2026

Summary

Plotly Express repeats the x-axis title under every facet column and the y-axis title beside every facet row. Plotly has no flag to fix this on an existing figure — the only built-in (make_subplots(x_title=..., y_title=...)) works at figure creation only and is not reachable through px (long-standing community request).

This PR makes faceted plots render one shared, centered label per axis instead:

  • New public helper share_axis_labels(fig): collapses repeated, identical axis titles into a single label per axis, usable on any figure (raw px, overlay output, etc.)
  • New shared_axis_labels kwarg on all plotting/accessor methods, on by default; pass shared_axis_labels=False for plotly's stock behavior

Design

  • The added labels use annotation specs byte-identical to plotly's own make_subplots(x_title=, y_title=) implementation — a sync test compares against real make_subplots output, so if plotly ever changes its styling we'll know
  • Titles are only collapsed when repeated and identical:
    • non-faceted figures → unchanged
    • subplots() combinations with differing titles → unchanged
    • secondary-y (overlaying) axes → never collapsed
  • Applied after simplify_facet_titles, so facet title post-processing and shared labels compose

Visual

Before After
"Air Temperature [K]" ×2 rows, "time" ×2 columns one of each, centered

Test plan

  • 11 new tests: helper behavior per facet direction, idempotency, no-facet no-op, secondary-y safety, differing-title safety, kwarg default/opt-out, imshow facets, and the make_subplots sync test
  • Existing imshow facet tests updated (annotation sets now include shared labels)
  • ruff, ruff format, mypy clean; 173 tests pass
  • Visually verified renders (facet grid, facet_col-only) via kaleido

🤖 Generated with Claude Code

Plotly Express repeats the x-axis title under every facet column and the
y-axis title beside every facet row, and exposes no built-in way to fix
this on an existing figure (make_subplots' x_title/y_title only work at
figure creation and are not reachable from px).

Add a public share_axis_labels(fig) helper that collapses repeated,
identical axis titles into one centered label per axis, using annotation
specs identical to plotly's built-in shared subplot titles (verified by a
sync test against make_subplots output). Titles are only collapsed when
actually repeated, so combined figures with differing subplot titles and
secondary-y figures pass through unchanged.

All plotting/accessor methods gain a shared_axis_labels kwarg, on by
default; pass shared_axis_labels=False for plotly's stock behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Warning

Review limit reached

@FBumann, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16fbbe45-b25e-49a2-9361-5882dafdab97

📥 Commits

Reviewing files that changed from the base of the PR and between 10cfda0 and e720f47.

📒 Files selected for processing (6)
  • tests/test_accessor.py
  • tests/test_figures.py
  • xarray_plotly/__init__.py
  • xarray_plotly/accessor.py
  • xarray_plotly/figures.py
  • xarray_plotly/plotting.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/shared-facet-axis-labels

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@FBumann FBumann merged commit 5a3bef8 into main Jun 3, 2026
11 checks passed
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.

1 participant