Title: BUGFIX: use true bbox for rasters in backend_mixed by brunobeltran · Pull Request #17182 · matplotlib/matplotlib · GitHub
Open Graph Title: BUGFIX: use true bbox for rasters in backend_mixed by brunobeltran · Pull Request #17182 · matplotlib/matplotlib
X Title: BUGFIX: use true bbox for rasters in backend_mixed by brunobeltran · Pull Request #17182 · matplotlib/matplotlib
Description: PR Summary WIP. Needs tests. Fixes #6827, and various other analogous bugs that may or may not have issues open. Right now, backend_mixed does something equivalent to (excuse the abuse of notation) bbox = int(bbox/72*image_dpi)*72/image_dpi to get the final width at which to place rastered output. The int() cast is required since rasterizing can only happen into integer numbers of pixels. This PR adds some methods to MixedModeRenderer that wrap each draw_* function, allowing us to manually keep around the original desired bbox of each rasterized component, allowing it to be scaled back to fit correctly. This means that for mixed-mode renders, dpi= is now a suggestion (the true dpi will typically be off by <1%, but can be off by quite a bit for very low dpi requests). However, most people using vector output care less about the exact dpi and care a lot about things not looking randomly out of alignment. This approach was suggested by @jklymak in the discussion of #16488. The tests will stop failing once I've reimplented all of * :meth:`draw_path` * :meth:`draw_image` * :meth:`draw_gouraud_triangle` * :meth:`draw_text` * :meth:`draw_markers` * :meth:`draw_path_collection` * :meth:`draw_quad_mesh` for MixedModeRenderer. Comparison with previous behavior Code import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.cm import numpy as np mpl.rcParams['figure.dpi'] = 20 fig, ax = plt.subplots(figsize=(2, 1.5)) ax.imshow(np.array([[0, 1], [1, 0]])) ax.axis('off') sm = matplotlib.cm.ScalarMappable() sm.set_array([]) plt.colorbar(sm) plt.savefig('test.svg') Old output Bboxes added in post, for emphasis: New output Bboxes align exactly PR Checklist Has Pytest style unit tests Code is Flake 8 compliant New features are documented, with examples if plot related Documentation is sphinx and numpydoc compliant Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way
Open Graph Description: PR Summary WIP. Needs tests. Fixes #6827, and various other analogous bugs that may or may not have issues open. Right now, backend_mixed does something equivalent to (excuse the abuse of notation)...
X Description: PR Summary WIP. Needs tests. Fixes #6827, and various other analogous bugs that may or may not have issues open. Right now, backend_mixed does something equivalent to (excuse the abuse of notation)...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/17182
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2aea0805-3ef5-56ea-b44e-f052937b5ad8 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D5EC:D3171:EB1728:137CE17:6A51BD7B |
| html-safe-nonce | 3c693947e863db3822bcc6599fe915e925752ad9111788035467eca1773403fa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUVDOkQzMTcxOkVCMTcyODoxMzdDRTE3OjZBNTFCRDdCIiwidmlzaXRvcl9pZCI6IjM3ODQ3NzkxNDA2OTMwODE0NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5b7c00cb2a92898ef3eb2dfa1360d867d24f39a4de58d10719cd7cf701720bfc |
| hovercard-subject-tag | pull_request:405380126 |
| 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/17182/files |
| twitter:image | https://avatars.githubusercontent.com/u/1475390?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1475390?s=400&v=4 |
| og:image:alt | PR Summary WIP. Needs tests. Fixes #6827, and various other analogous bugs that may or may not have issues open. Right now, backend_mixed does something equivalent to (excuse the abuse of notation)... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width