Title: [Doc]: Gallery example showing 3D slice planes · Issue #28239 · matplotlib/matplotlib · GitHub
Open Graph Title: [Doc]: Gallery example showing 3D slice planes · Issue #28239 · matplotlib/matplotlib
X Title: [Doc]: Gallery example showing 3D slice planes · Issue #28239 · matplotlib/matplotlib
Description: @timhoffm suggested in #3919 (comment) that we make a gallery example for plotting X Y Z planar slices through a volume. His result and its code: import matplotlib.pyplot as plt import numpy as np def plot_quadrants(ax, array, fixed_coor...
Open Graph Description: @timhoffm suggested in #3919 (comment) that we make a gallery example for plotting X Y Z planar slices through a volume. His result and its code: import matplotlib.pyplot as plt import numpy as np ...
X Description: @timhoffm suggested in #3919 (comment) that we make a gallery example for plotting X Y Z planar slices through a volume. His result and its code: import matplotlib.pyplot as plt import numpy as np ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28239
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Doc]: Gallery example showing 3D slice planes","articleBody":"@timhoffm suggested in https://github.com/matplotlib/matplotlib/issues/3919#issuecomment-2116282472 that we make a gallery example for plotting X Y Z planar slices through a volume.\r\n\r\nHis result and its code:\r\n\r\n\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\ndef plot_quadrants(ax, array, fixed_coord, cmap):\r\n \"\"\"For a given 3d *array* plot a plane with *fixed_coord*, using four individual quadrants.\"\"\"\r\n nx, ny, nz = array.shape\r\n index = {\r\n 'x': (nx//2, slice(None), slice(None)),\r\n 'y': (slice(None), ny//2, slice(None)),\r\n 'z': (slice(None), slice(None), nz//2),\r\n }[fixed_coord]\r\n plane_data = array[index]\r\n\r\n n0, n1 = plane_data.shape\r\n quadrants = [\r\n plane_data[:n0//2, :n1//2],\r\n plane_data[:n0//2, n1//2:],\r\n plane_data[n0//2:, :n1//2],\r\n plane_data[n0//2:, n1//2:]\r\n ]\r\n\r\n min_val = array.min()\r\n max_val = array.max()\r\n \r\n cmap = plt.get_cmap(cmap)\r\n \r\n for i, quadrant in enumerate(quadrants):\r\n facecolors = cmap((quadrant - min_val) / (max_val-min_val))\r\n if fixed_coord == 'x':\r\n Y, Z = np.mgrid[0:ny//2, 0:nz//2]\r\n X = nx//2 * np.ones_like(Y)\r\n Y_offset = (i // 2) * ny//2\r\n Z_offset = (i % 2) * nz//2\r\n ax.plot_surface(X, Y + Y_offset, Z + Z_offset, rstride=1, cstride=1, facecolors=facecolors, shade=False)\r\n elif fixed_coord == 'y':\r\n X, Z = np.mgrid[0:nx//2, 0:nz//2]\r\n Y = ny//2 * np.ones_like(X)\r\n X_offset = (i // 2) * nx//2\r\n Z_offset = (i % 2) * nz//2\r\n ax.plot_surface(X + X_offset, Y, Z + Z_offset, rstride=1, cstride=1, facecolors=facecolors, shade=False)\r\n elif fixed_coord == 'z':\r\n X, Y = np.mgrid[0:nx//2, 0:ny//2]\r\n Z = nz//2 * np.ones_like(X)\r\n X_offset = (i // 2) * nx//2\r\n Y_offset = (i % 2) * ny//2\r\n ax.plot_surface(X + X_offset, Y + Y_offset, Z, rstride=1, cstride=1, facecolors=facecolors, shade=False)\r\n\r\n\r\ndef figure_3D_array_slices(array, cmap=None):\r\n \"\"\"Plot a 3d array using three intersecting centered planes.\"\"\"\r\n fig = plt.figure()\r\n ax = fig.add_subplot(projection='3d')\r\n ax.set_box_aspect(array.shape)\r\n plot_quadrants(ax, array, 'x', cmap=cmap)\r\n plot_quadrants(ax, array, 'y', cmap=cmap)\r\n plot_quadrants(ax, array, 'z', cmap=cmap)\r\n return fig, ax\r\n\r\n\r\nnx, ny, nz = 70, 100, 50\r\nr_square = (np.mgrid[-1:1:1j*nx, -1:1:1j*ny, -1:1:1j*nz]**2).sum(0)\r\n\r\nfigure_3D_array_slices(r_square, cmap='viridis_r')\r\nplt.show()\r\n```\r\n","author":{"url":"https://github.com/scottshambaugh","@type":"Person","name":"scottshambaugh"},"datePublished":"2024-05-16T23:02:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/28239/matplotlib/issues/28239"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:79daf3b3-dba9-2bc5-b936-87fb63653d4f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A324:299504:945A05:C77A29:6A530E38 |
| html-safe-nonce | d494f6a496fdcc55566e7ad8375ab42f435459fbfe5c4fc77b57fec1cb48f8a6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzI0OjI5OTUwNDo5NDVBMDU6Qzc3QTI5OjZBNTMwRTM4IiwidmlzaXRvcl9pZCI6IjY5NTc5Nzg5Nzg3NTM2MTMzNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 747090d21707f44d5400d9299c8a9252942841208d79ba317dfed147fa158e52 |
| hovercard-subject-tag | issue:2301519135 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/matplotlib/matplotlib/28239/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8dfe4455f464f0c90de981034a3a53f3f8c03559cd29e9539249113f199d52d9/matplotlib/matplotlib/issues/28239 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8dfe4455f464f0c90de981034a3a53f3f8c03559cd29e9539249113f199d52d9/matplotlib/matplotlib/issues/28239 |
| og:image:alt | @timhoffm suggested in #3919 (comment) that we make a gallery example for plotting X Y Z planar slices through a volume. His result and its code: import matplotlib.pyplot as plt import numpy as np ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scottshambaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width