Title: ENH: add geometric axlim clipping for 3D surfaces and line collections by DanielBetschinske · Pull Request #31732 · matplotlib/matplotlib · GitHub
Open Graph Title: ENH: add geometric axlim clipping for 3D surfaces and line collections by DanielBetschinske · Pull Request #31732 · matplotlib/matplotlib
X Title: ENH: add geometric axlim clipping for 3D surfaces and line collections by DanielBetschinske · Pull Request #31732 · matplotlib/matplotlib
Description: PR summary Related to #25804. This PR adds an opt-in geometric axes-limit clipping mode for selected mplot3d polygon and line artists. Currently, axlim_clip=True hides/masks surface patches or line segments when vertices fall outside the current 3D axes view limits. For surfaces and wireframes this can leave visible gaps at the axes-limit boundary. This PR keeps the existing behavior as the default: ax.plot_surface(..., axlim_clip=True) ax.plot_wireframe(..., axlim_clip=True) and adds a new explicit mode: ax.plot_surface(..., axlim_clip=True, axlim_clip_mode="clip") ax.plot_wireframe(..., axlim_clip=True, axlim_clip_mode="clip") With axlim_clip_mode="clip", surface polygons and wireframe line segments are geometrically clipped to the six planes of the current 3D axes view-limit box. The implementation adds private clipping helpers in mpl_toolkits.mplot3d.art3d for: clipping 3D polygons against an axis-aligned box, clipping 3D line segments against an axis-aligned box. The new keyword is forwarded from Axes3D.plot_surface and Axes3D.plot_wireframe to the underlying Poly3DCollection and Line3DCollection. This PR intentionally keeps the scope limited to surfaces and line collections. Point-like artists such as scatter and text continue to use the existing hide/mask behavior, because they do not have 3D geometry that can be meaningfully cut. Minimum example: import numpy as np import matplotlib.pyplot as plt from matplotlib import cm fig, axs = plt.subplots( 1, 3, subplot_kw={"projection": "3d"}, figsize=(10, 4), layout="constrained", ) x = np.arange(-5, 5, 0.25) y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(x, y) Z = np.sin(np.hypot(X, Y)) cases = [ ("unclipped", dict(axlim_clip=False)), ('axlim_clip_mode="hide"', dict(axlim_clip=True, axlim_clip_mode="hide")), ('axlim_clip_mode="clip"', dict(axlim_clip=True, axlim_clip_mode="clip")), ] for ax, (title, clip_kwargs) in zip(axs, cases): ax.plot_surface( X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False, **clip_kwargs, ) ax.set_title(title) ax.set_xlim(-3.2, 3.2) ax.set_ylim(-3.0, 2.6) ax.set_zlim(-0.45, 0.85) plt.show() AI Disclosure I used ChatGPT to help prototype the clipping approach, identify edge cases, draft tests and gallery-example text, and iterate on implementation details. I reviewed and tested the resulting changes locally before submitting this PR. PR checklist [N/A] "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested Plotting related features are demonstrated in an example New Features and API Changes are noted with a directive and release note Documentation complies with general and docstring guidelines
Open Graph Description: PR summary Related to #25804. This PR adds an opt-in geometric axes-limit clipping mode for selected mplot3d polygon and line artists. Currently, axlim_clip=True hides/masks surface patches or line...
X Description: PR summary Related to #25804. This PR adds an opt-in geometric axes-limit clipping mode for selected mplot3d polygon and line artists. Currently, axlim_clip=True hides/masks surface patches or line...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31732
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:be7eb907-18aa-d934-4eca-938a5df7f4c9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | ECEE:1111EE:15681FF:1D202C6:6A522477 |
| html-safe-nonce | ee4c02cf2854d85b30eec2e3bdfc52ad14f3b7002a6d188c5c2cb261bf308838 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQ0VFOjExMTFFRToxNTY4MUZGOjFEMjAyQzY6NkE1MjI0NzciLCJ2aXNpdG9yX2lkIjoiNDQ3ODIzNTA0Njk1MjcwNzE5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aba3b9010c883913fbafb9b3832eada77ea52ca28467ba0ced8c5261af136256 |
| hovercard-subject-tag | pull_request:3731314685 |
| 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/31732/files |
| twitter:image | https://avatars.githubusercontent.com/u/160840538?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/160840538?s=400&v=4 |
| og:image:alt | PR summary Related to #25804. This PR adds an opt-in geometric axes-limit clipping mode for selected mplot3d polygon and line artists. Currently, axlim_clip=True hides/masks surface patches or line... |
| 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