Skip to content

Fix colorbar gallery placement and domains [mpl compatibility] - #246

Closed
sselvakumaran wants to merge 12 commits into
mainfrom
agent/fix-matplotlib-colorbar-gallery
Closed

Fix colorbar gallery placement and domains [mpl compatibility]#246
sselvakumaran wants to merge 12 commits into
mainfrom
agent/fix-matplotlib-colorbar-gallery

Conversation

@sselvakumaran

Copy link
Copy Markdown
Contributor

What changed

  • accept Matplotlib-compatible colorbar(location=..., anchor=..., shrink=...)
  • place horizontal and vertical colorbars consistently in browser, SVG, and native PNG renderers
  • render minor colorbar ticks across all three paths
  • exclude masked samples from inferred colorbar domains

Why

The official Matplotlib 3.11 colorbar_basics.py example uses a shrunken/anchored left colorbar and minor ticks. xy previously rejected those options; it also let masked sentinel values distort the second panel's domain.

Official reference: https://matplotlib.org/stable/gallery/color/colorbar_basics.html

Before, Matplotlib reference, and after

The final panel was rendered with this PR plus #245, because the official script also requires the independently missing Reds_r colormap. With both branches combined, the exact gallery script completes and the colorbar orientation, placement, domain, extension, and minor ticks are technically correct.

Scope

This does not add colorbar(cax=...); subplots_adjust.py remains a separate blocker. It also does not touch autoscale margins or the tick-spacing work owned by #240.

Validation

  • 544 passed, 65 skipped across the full pyplot suite
  • Ruff check and format
  • TypeScript typecheck
  • production JavaScript bundle build
  • exact official gallery render compared with Matplotlib 3.11

@codspeed-hq

codspeed-hq Bot commented Jul 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 103 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing agent/fix-matplotlib-colorbar-gallery (016c43f) with main (9b08085)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@sselvakumaran

Copy link
Copy Markdown
Contributor Author

in the red plot, the the legend is smaller, but it probably should not be forced to show more ticks to accomodate. the red one should only have 3, bc in this version the tick spacing is too little bc theres so many ticks / numbers.

@sselvakumaran sselvakumaran changed the title Fix Matplotlib colorbar gallery placement and domains Fix colorbar gallery placement and domains [mpl compatibility] Jul 24, 2026

sselvakumaran commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the short red colorbar tick density in 6d53511, with rendered-output coverage in a6e3822.

Correction to the earlier evidence: that image omitted #245, so it rendered the fallback blue palette and did not represent the combined gallery state. This replacement reruns the exact Matplotlib 3.11 colorbar_basics source in all three panels:

Matplotlib 3.11 / combined before / combined fixed

Full uncropped colorbar_basics renders: Matplotlib 3.11 reference, combined #245 plus pre-fix #246 with seven crowded red ticks, and combined #245 plus fixed #246 with three readable red ticks

The renders are full and uncropped. XY is shown normalized from its native 2x export only so all three rows have the same displayed dimensions.

Verification of the corrected combined render:

  • the short Reds_r scale has the right direction: near-zero is white at the top and approximately -2 is dark red at the bottom
  • sampled fixed endpoints are (255, 245, 240) at the top and (103, 0, 13) at the bottom
  • the pre-fix SVG has seven labels: -1.75, -1.5, -1.25, -1, -0.75, -0.5, -0.25
  • the fixed SVG has the same three major labels as Matplotlib: -1.5, -1, -0.5
  • the image is pinned to immutable commit 650dd2b; the asset-only cleanup head is 8e65668, so the PNG is not present in the branch tip

The underlying #246 code at bc13c2c had all checks green; the two later commits only add and remove this corrected evidence image.

@sselvakumaran

Copy link
Copy Markdown
Contributor Author

Fresh CI confirms the earlier red was transient: Test (Rust + Python + JS) passed on a6e3822, including the exact previously failing Headless render smoke (stdlib + Chromium) step. CodSpeed also refreshed against a6e3822 and reports no performance alteration (102 benchmarks untouched, 1 skipped). The Matplotlib 3.11 reference compatibility, benchmark methodology, cross-library benchmark, docs, accessibility, CodeQL, and Python 3.11 checks are green as well.

@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: 30ad70dc-80e8-4354-9c02-b996553c3bbb

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/fix-matplotlib-colorbar-gallery

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

Document the shared colorbar spec object's location/anchor/shrink and
minor-tick options, their defaults and coordinate conventions, and the
exclusion of masked samples from an inferred colorbar domain.
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