Title: [Bug]: Issue with setting axis limits on 3D plots · Issue #25804 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Issue with setting axis limits on 3D plots · Issue #25804 · matplotlib/matplotlib
X Title: [Bug]: Issue with setting axis limits on 3D plots · Issue #25804 · matplotlib/matplotlib
Description: Bug summary I have created 3D surface plots using matplotlib as described [here]. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such as Axes.set_xlim() (whether or not Axes...
Open Graph Description: Bug summary I have created 3D surface plots using matplotlib as described [here]. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such...
X Description: Bug summary I have created 3D surface plots using matplotlib as described [here]. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/25804
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Issue with setting axis limits on 3D plots","articleBody":"### Bug summary\r\n\r\nI have created 3D surface plots using matplotlib as described [[here](https://matplotlib.org/stable/gallery/mplot3d/subplot3d.html)]. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such as Axes.set_xlim() (whether or not Axes.set_xbound()is used) limit the axis but not the data. The data is plotted and appears to continue beyond the axis limits.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\naxes = []\r\nfig0, ax0 = plt.subplots(subplot_kw={\"projection\": \"3d\"})\r\naxes.append(ax0)\r\n\r\nsurf0 = axes[0].plot_surface(DS_ee, DS_cc, DS_array, cmap=cm.jet, linewidth=0, antialiased=False)\r\n\r\naxes[0].xaxis.set_major_locator(MultipleLocator(10))\r\naxes[0].xaxis.set_minor_locator(MultipleLocator(2))\r\naxes[0].yaxis.set_major_locator(MultipleLocator(1))\r\naxes[0].yaxis.set_minor_locator(MultipleLocator(0.2))\r\n\r\naxes[0].set_zlabel('Default Spectrum [photons/keV/pixel]', fontsize=7)\r\naxes[0].set_xlim(left=0, right=10)\r\naxes[0].set_zlim(0, 3000)\r\n# axes[0].set_xbound(0, 10)\r\n# axes[0].set_zbound(0, 3000)\r\n\r\nfor t in axes[0].xaxis.get_major_ticks(): t.label.set_fontsize(6)\r\nfor t in axes[0].yaxis.get_major_ticks(): t.label.set_fontsize(6)\r\nfor t in axes[0].zaxis.get_major_ticks(): t.label.set_fontsize(6)\r\n\r\naxes[0].grid(False)\r\naxes[0].view_init(elev=elev_angle, azim=azim_angle)\r\naxes[0].set(xlabel='E [keV]', ylabel=ylabel)\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\nSurface plot after using `Axes.set_xlim(left=0, right=10)`:\r\n\r\n\u003cimg width=\"528\" alt=\"Screenshot 2023-04-28 at 2 53 45 PM\" src=\"https://user-images.githubusercontent.com/14204540/235541107-0d3e0e92-dd65-424f-a985-5dd15e71bc80.png\"\u003e\r\n\r\nSurface plot after using using `Axes.set_xlim(left=0, right=10)` and `axes[0].set_zlim(0, 3000)`: \r\n\r\n\u003cimg width=\"528\" alt=\"Screenshot 2023-04-28 at 2 54 18 PM\" src=\"https://user-images.githubusercontent.com/14204540/235541190-040cae0f-a3de-4ded-8646-d422963e47da.png\"\u003e\r\n\r\n\r\n### Expected outcome\r\n\r\nThe image should look like the following but with the E axis ending at 10 keV and the vertical axis ending at 3000:\r\n\r\n\u003cimg width=\"528\" alt=\"Screenshot 2023-04-28 at 2 51 16 PM\" src=\"https://user-images.githubusercontent.com/14204540/235541426-c979f5fe-95dd-4ea5-91b3-1dc963a37af6.png\"\u003e\r\n\r\n\r\n### Additional information\r\n\r\nI'm running the code that imports matplotlib in Spyder. I can share upon request the full code and input files needed to reproduce the error.\r\n\r\nI tried all the suggestions in [this post](https://stackoverflow.com/questions/17734587/why-is-set-xlim-not-setting-the-x-limits-in-my-figure) and also [this one](https://stackoverflow.com/questions/48986956/correctly-setting-the-axes-limits-in-3d-plots) and none worked. For example, I tried:\r\n\r\n```\r\naxes[0].set_xlim(left=0, right=10)\r\naxes[0].set_zlim(0, 3000)\r\n```\r\n\r\nAlso\r\n\r\n```\r\naxes[0].set_xlim(min=0, max=10)\r\naxes[0].set_zlim(0, 3000)\r\n```\r\nand\r\n\r\n```\r\naxes[0].set_xlim(left=0, right=10)\r\naxes[0].set_zlim(0, 3000)\r\naxes[0].set_xbound(0, 10)\r\naxes[0].set_zbound(0, 3000)\r\n```\r\nand\r\n\r\n```\r\naxes[0].set_xlim3d(left=0, right=10)\r\naxes[0].set_zlim3d(0, 3000)\r\n```\r\n\r\n### Operating system\r\n\r\nOS/X Ventura 13.3.1\r\n\r\n### Matplotlib Version\r\n\r\n3.5.2\r\n\r\n### Matplotlib Backend\r\n\r\nQt5Agg\r\n\r\n### Python version\r\n\r\n3.9.13\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nNone","author":{"url":"https://github.com/nbfazel","@type":"Person","name":"nbfazel"},"datePublished":"2023-05-01T23:00:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":20},"url":"https://github.com/25804/matplotlib/issues/25804"}
| 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:e5edb53a-9077-6979-a0f5-3367f45a7869 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E464:1159AF:7E55B4:A96B17:6A52ABED |
| html-safe-nonce | acac09a83ff1720baeee514e7769a1a622c40e4966855f25b66f2b89364ad266 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDY0OjExNTlBRjo3RTU1QjQ6QTk2QjE3OjZBNTJBQkVEIiwidmlzaXRvcl9pZCI6IjM0MDkyNjQxNjcxMTQ0MTkxODEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d3422bd861b94f3c49df52faf59f01945418d9d3df4f33b19bc8ea29ec95084d |
| hovercard-subject-tag | issue:1691526153 |
| 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/25804/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c2ac35389cd987b2461fbe0370eaf1cde86bff13e8dd16b22650cf2ae9f30d7/matplotlib/matplotlib/issues/25804 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c2ac35389cd987b2461fbe0370eaf1cde86bff13e8dd16b22650cf2ae9f30d7/matplotlib/matplotlib/issues/25804 |
| og:image:alt | Bug summary I have created 3D surface plots using matplotlib as described [here]. Everything works except when I set the axis limits. Then the plots look very strange. It appears that commands such... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nbfazel |
| 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