Title: Fix PDF bloat for off-axis scatter with per-point colors by FazeelUsmani · Pull Request #30746 · matplotlib/matplotlib · GitHub
Open Graph Title: Fix PDF bloat for off-axis scatter with per-point colors by FazeelUsmani · Pull Request #30746 · matplotlib/matplotlib
X Title: Fix PDF bloat for off-axis scatter with per-point colors by FazeelUsmani · Pull Request #30746 · matplotlib/matplotlib
Description: Fixes #2488 PR summary Problem When using scatter() with per-point colors and then moving the axes limits so all points are off-screen, the PDF backend still writes all marker paths to the file, resulting in unnecessarily large PDFs (~400KB instead of ~7KB for 1000 points). Solution Added bounds checking in draw_path_collection (backend_pdf.py:2121-2125) to skip markers outside the visible canvas. This mirrors the existing optimization already present in draw_markers (lines 2157-2159). Implementation Check marker offsets (xo, yo) against canvas bounds (0, 0) to (width*72, height*72) Skip the output() call for out-of-bounds markers Conservative, backend-specific change (PDF only) No API changes or user-facing behavior modifications Reproduction Example import numpy as np import matplotlib.pyplot as plt x = np.random.random(1000) y = np.random.random(1000) c = np.random.random(1000) # Before fix: ~410 KB PDF # After fix: ~7-15 KB PDF plt.figure() plt.scatter(x, y, c=c) plt.xlim(20, 30) # Move all points off-axis (data is 0-1 range) plt.savefig('scatter_offaxis.pdf') Testing Added three new tests in test_backend_pdf.py: test_scatter_offaxis_colored_pdf_size test_scatter_offaxis_colored_visual test_scatter_mixed_onoff_axis PR checklist "Fixes #2488" is in the body of the PR description to [(https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)] New and changed code is [tested](https://matplotlib.org/devdocs/devel/testing.html) [N/A] Plotting related features are demonstrated in an [example](https://matplotlib.org/devdocs/devel/document.html#write-examples-and-tutorials) [N/A] New Features and API Changes are noted with a [directive and release note](https://matplotlib.org/devdocs/devel/api_changes.html#announce-changes-deprecations-and-new-features) [N/A] Documentation complies with [general](https://matplotlib.org/devdocs/devel/document.html#write-rest-pages) and [docstring](https://matplotlib.org/devdocs/devel/document.html#write-docstrings) guidelines
Open Graph Description: Fixes #2488 PR summary Problem When using scatter() with per-point colors and then moving the axes limits so all points are off-screen, the PDF backend still writes all marker paths to the file, re...
X Description: Fixes #2488 PR summary Problem When using scatter() with per-point colors and then moving the axes limits so all points are off-screen, the PDF backend still writes all marker paths to the file, re...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30746
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:76b4ec3a-5667-1fa8-5590-0c5f3567244c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BF32:A56AD:FD776E:17195E2:6A4E35C2 |
| html-safe-nonce | 759c51f729ff29affc856aa2571c289863ca462feb1de027c71569e91f84370b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjMyOkE1NkFEOkZENzc2RToxNzE5NUUyOjZBNEUzNUMyIiwidmlzaXRvcl9pZCI6IjMxMDk5MDY4MzIwNzM1Njk3MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5fd0c2dbaaab66b2553f68a846d04d101254577db2237c3bfaa55f958129a020 |
| hovercard-subject-tag | pull_request:3002109871 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/30746/files |
| twitter:image | https://avatars.githubusercontent.com/u/8823157?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8823157?s=400&v=4 |
| og:image:alt | Fixes #2488 PR summary Problem When using scatter() with per-point colors and then moving the axes limits so all points are off-screen, the PDF backend still writes all marker paths to the file, re... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 42a6d378d7587a44c93aca255096cd66b7c8eb2d |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width