Skip to content

Reserve Matplotlib legend layout space [mpl compatibility]#254

Draft
sselvakumaran wants to merge 4 commits into
agent/line-legend-gallery-compatfrom
agent/legend-layout-gallery-compat
Draft

Reserve Matplotlib legend layout space [mpl compatibility]#254
sselvakumaran wants to merge 4 commits into
agent/line-legend-gallery-compatfrom
agent/legend-layout-gallery-compat

Conversation

@sselvakumaran

Copy link
Copy Markdown
Contributor

Summary

  • reserve plot padding for anchored legends from their measured title + entry geometry
  • match Matplotlib's font-relative legend defaults (borderpad=.4, labelspacing=.5, borderaxespad=.5, 2em handles and column spacing)
  • keep SVG, raster, and browser legend positioning/sizing consistent
  • preserve literal $ labels such as the price legend's $ 2.00

This is stacked on #248 (agent/line-legend-gallery-compat).

Exact Matplotlib gallery comparisons

Outside top legend: horizontal_barchart_distribution

The previous legend touched the axes border/first row. The new measured reservation leaves the same ~0.5-font border-to-axes gap as Matplotlib.

Matplotlib 3.11 vs latest PR heads vs this PR for the horizontal bar legend

The clipped left category labels (Question appearing as estion) are intentionally not claimed as fixed here: the exact latest-heads union shows #240 does not resolve that canvas-gutter defect. A separate general gutter follow-up is required for full visual completion.

Titled scatter legends: scatter_with_legend

The previous static layout truncated Ranking to Ra... and undersized title/entry bounds. The new boxes use the title and every entry when measuring width and height.

Matplotlib 3.11 vs latest PR heads vs this PR for titled scatter legends

Verification

  • 547 passed, 65 skipped in tests/pyplot
  • focused legend/rc/grid tests: 22 passed
  • TypeScript typecheck and browser bundle build pass
  • exact Matplotlib 3.11 gallery scripts rerendered at 100 DPI
  • 88-example execution totals unchanged: 55 paired scripts / 79 paired figures; no execution-count regression
  • ruff check and git diff --check pass

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 11987504-7979-4284-95d3-df974a765b65

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/legend-layout-gallery-compat

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

@codspeed-hq

codspeed-hq Bot commented Jul 24, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 15.87%

❌ 1 regressed benchmark
✅ 101 untouched benchmarks
⏩ 2 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_pyramid_compose 9.3 ms 11 ms -15.87%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing agent/legend-layout-gallery-compat (12d0cb9) with agent/line-legend-gallery-compat (cf7cae4)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sselvakumaran sselvakumaran changed the title Reserve Matplotlib legend layout space Reserve Matplotlib legend layout space [mpl compatibility] Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant