Skip to content

Fix PDF marker culling with translated master transform#32003

Closed
Ayush-0918 wants to merge 1 commit into
matplotlib:mainfrom
Ayush-0918:fix-pdf-hexbin-culling
Closed

Fix PDF marker culling with translated master transform#32003
Ayush-0918 wants to merge 1 commit into
matplotlib:mainfrom
Ayush-0918:fix-pdf-hexbin-culling

Conversation

@Ayush-0918

Copy link
Copy Markdown

closes #31999

PR summary

This PR fixes incorrect marker culling in the PDF backend when master_transform includes a translation.

The visibility check was using untranslated marker coordinates, which could incorrectly skip markers that become visible after the translation is applied. This could lead to missing markers in the generated PDF.

This change applies the translated coordinates only for the visibility check, while keeping the existing rendering coordinates unchanged. This preserves the current rendering behavior and fixes the culling logic.

Testing

AI Disclosure

I used ChatGPT as a debugging assistant to help reason about the rendering logic and discuss possible approaches. I implemented the final solution myself, verified the behavior locally, and reviewed the final changes before submitting this pull request.

PR checklist

Copilot AI review requested due to automatic review settings July 5, 2026 19:53
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses incorrect marker culling in the PDF backend’s draw_path_collection optimization when master_transform includes a translation (notably impacting hexbin where offsets may be delta-transformed).

Changes:

  • Adjusts the visibility/culling check to account for the translation component of master_transform when determining whether a marker is within (or intersects) the PDF canvas.
  • Keeps the existing rendering coordinates unchanged while altering only the culling decision path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2038 to +2042
m = master_transform.get_matrix()
tx = m[0, 2]
ty = m[1, 2]

xo2 = xo + tx
Comment on lines 2054 to 2057
extent_x, extent_y = path_extent_map[path_id]
if not (-extent_x <= xo <= canvas_width + extent_x
and -extent_y <= yo <= canvas_height + extent_y):
if not (-extent_x <= xo2 <= canvas_width + extent_x
and -extent_y <= yo2 <= canvas_height + extent_y):
continue
@rcomer

rcomer commented Jul 6, 2026

Copy link
Copy Markdown
Member

Thank you for your interest in contributing to Matplotlib. There is already PR #32000 for this issue, and we generally prioritise ones that are opened first. So closing this here.

@rcomer rcomer closed this Jul 6, 2026
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

3 participants