Title: Don't modify input path codes when chunking in Agg by yqtian-se · Pull Request #32640 · matplotlib/matplotlib · GitHub
Open Graph Title: Don't modify input path codes when chunking in Agg by yqtian-se · Pull Request #32640 · matplotlib/matplotlib
X Title: Don't modify input path codes when chunking in Agg by yqtian-se · Pull Request #32640 · matplotlib/matplotlib
Description: PR summary When agg.path.chunksize is set, RendererAgg.draw_path splits a long path into chunks and sets the first code of each chunk to MOVETO. The chunk codes were a slice (a view) of path.codes, so this wrote into the caller's path. After one draw, the path is permanently broken at every chunk start. For example, a PathPatch keeps the gaps on later draws, even with chunking turned off or when saving to another format. Drawing a read-only path this way raised ValueError: assignment destination is read-only. import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import PathPatch from matplotlib.path import Path n = 300 codes = np.full(n, Path.LINETO, dtype=Path.code_type) codes[0] = Path.MOVETO path = Path(np.column_stack([np.linspace(0, 1, n), np.sin(np.linspace(0, 6 * np.pi, n))]), codes) before = path.codes.copy() fig, ax = plt.subplots() ax.add_patch(PathPatch(path, fill=False)) with mpl.rc_context({"agg.path.chunksize": 120}): fig.canvas.draw() print(np.nonzero(path.codes != before)[0]) # [100 200] on main, [] with this PR Actual (main) vs expected (this PR): after one chunked draw, the next normal draw is missing a stroke at each chunk start. The fix copies the chunk's codes before changing them. Vertices are only read, so they need no copy. Added test_chunksize_does_not_modify_path in test_agg.py. It fails on main and passes with this change. AI Disclosure This bug was found while reading and analyzing the code with the help of Claude. PR quality check Use an expressive title, e.g. "Fix title font property precedence" New and changed code is tested [N/A] Plotting related features are demonstrated in an example [N/A] New features and API changes have release notes [N/A] Documentation complies with general and docstring guidelines
Open Graph Description: PR summary When agg.path.chunksize is set, RendererAgg.draw_path splits a long path into chunks and sets the first code of each chunk to MOVETO. The chunk codes were a slice (a view) of path.codes,...
X Description: PR summary When agg.path.chunksize is set, RendererAgg.draw_path splits a long path into chunks and sets the first code of each chunk to MOVETO. The chunk codes were a slice (a view) of path.codes,...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/32640
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:305d0867-4690-f831-f044-6e65176e40cf |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A506:1E1C:66BB4F:8EF697:6B069485 |
| html-safe-nonce | b0feb2a9cd7cd0152f8bb7cbe1ea5521af4ee540953e5cf532ac732234aeaa1d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTA2OjFFMUM6NjZCQjRGOjhFRjY5Nzo2QjA2OTQ4NSIsInZpc2l0b3JfaWQiOiI1NTU5NTMwNDcyODk3NjgwNTE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d0294c422838e113d1b470e1096bd0ff08210248c3d4fa62b4971613caba577c |
| hovercard-subject-tag | pull_request:5438404860 |
| 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/32640/files |
| twitter:image | https://avatars.githubusercontent.com/u/41743566?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/41743566?s=400&v=4 |
| og:image:alt | PR summary When agg.path.chunksize is set, RendererAgg.draw_path splits a long path into chunks and sets the first code of each chunk to MOVETO. The chunk codes were a slice (a view) of path.codes,... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a |
| 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 | 6d3909414814ff86ce7da4c51a0f4918a13fb41b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width