Fix PDF path collection culling for `hexbin` offsets by yuzie007 · Pull Request #32000 · matplotlib/matplotlib · GitHub
Skip to content

Fix PDF path collection culling for hexbin offsets#32000

Open
yuzie007 wants to merge 2 commits into
matplotlib:mainfrom
yuzie007:fix-pdf-draw-path-collection
Open

Fix PDF path collection culling for hexbin offsets#32000
yuzie007 wants to merge 2 commits into
matplotlib:mainfrom
yuzie007:fix-pdf-draw-path-collection

Conversation

@yuzie007

@yuzie007 yuzie007 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

PR summary

This PR fixes a PDF backend regression where visible hexbin cells can be incorrectly skipped in Matplotlib 3.11.0.

Closes #31999.

PR #30746 added path collection culling to the PDF backend to avoid bloated PDFs when many colored scatter markers are fully outside the canvas. That optimization works for scatter, where transformed offsets correspond to marker centers in canvas coordinates. However, hexbin uses a repeated hexagon path with offsets transformed by AffineDeltaTransform(self.transData). Those transformed offsets are displacements, not absolute canvas-space marker
centers.

The PDF backend was culling collections by checking the transformed offset plus an approximate marker extent. For hexbin, this can classify visible cells as off-canvas, especially when offsets are negative, so the PDF output loses part of the plot while raster output renders correctly.

This PR keeps the optimization from #30746, but changes the culling check to use the actual transformed reusable path bounds translated by each offset. This preserves PDF size improvements for truly off-canvas scatter markers while correctly rendering hexbin and other collections whose transformed offsets are not absolute marker centers. This fix make the example in #31999 work as expected.

A PDF regression test for hexbin with negative offsets, compared against an equivalent shifted reference.

AI Disclosure

Agentic AI was employed to identify the origin of the issue, make the original fix, add the original test, and write the original issue and the PR description. The AI suggestions were reviewed and polished by human.

PR checklist

@yuzie007 yuzie007 force-pushed the fix-pdf-draw-path-collection branch from 1cec52b to 3e5af6f Compare July 5, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PDF backend culls visible hexbin cells after path collection optimization

1 participant