Title: [Bug]: Crash when adding clabels to subfigures · Issue #23173 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Crash when adding clabels to subfigures · Issue #23173 · matplotlib/matplotlib
X Title: [Bug]: Crash when adding clabels to subfigures · Issue #23173 · matplotlib/matplotlib
Description: Bug summary Adding a clabel to a contour plot of a subfigure results in a traceback. Code for reproduction # Taken from the Contour Demo example delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.mesh...
Open Graph Description: Bug summary Adding a clabel to a contour plot of a subfigure results in a traceback. Code for reproduction # Taken from the Contour Demo example delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np...
X Description: Bug summary Adding a clabel to a contour plot of a subfigure results in a traceback. Code for reproduction # Taken from the Contour Demo example delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/23173
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Crash when adding clabels to subfigures","articleBody":"### Bug summary\n\nAdding a clabel to a contour plot of a subfigure results in a traceback.\n\n### Code for reproduction\n\n```python\n# Taken from the Contour Demo example\r\ndelta = 0.025\r\nx = np.arange(-3.0, 3.0, delta)\r\ny = np.arange(-2.0, 2.0, delta)\r\nX, Y = np.meshgrid(x, y)\r\nZ1 = np.exp(-(X**2) - Y**2)\r\nZ2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2)\r\nZ = (Z1 - Z2) * 2\r\n\r\nfig = plt.figure()\r\nfigs = fig.subfigures(nrows=1, ncols=2)\r\n\r\nfor f in figs:\r\n ax = f.subplots()\r\n CS = ax.contour(X, Y, Z)\r\n ax.clabel(CS, inline=True, fontsize=10)\r\n ax.set_title(\"Simplest default with labels\")\r\n\r\nplt.show()\n```\n\n\n### Actual outcome\n\n```\r\n ax.clabel(CS, inline=True, fontsize=10)\r\n File \"/usr/lib/python3.9/site-packages/matplotlib/axes/_axes.py\", line 6335, in clabel\r\n return CS.clabel(levels, **kwargs)\r\n File \"/usr/lib/python3.9/site-packages/matplotlib/contour.py\", line 235, in clabel\r\n self.labels(inline, inline_spacing)\r\n File \"/usr/lib/python3.9/site-packages/matplotlib/contour.py\", line 582, in labels\r\n lw = self._get_nth_label_width(idx)\r\n File \"/usr/lib/python3.9/site-packages/matplotlib/contour.py\", line 285, in _get_nth_label_width\r\n .get_window_extent(mpl.tight_layout.get_renderer(fig)).width)\r\n File \"/usr/lib/python3.9/site-packages/matplotlib/tight_layout.py\", line 206, in get_renderer\r\n if fig._cachedRenderer:\r\nAttributeError: 'SubFigure' object has no attribute '_cachedRenderer'\r\n```\n\n### Expected outcome\n\nThe two subfigures appearing side by side, each showing the Contour Demo example\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nGentoo\n\n### Matplotlib Version\n\n3.5.2\n\n### Matplotlib Backend\n\nQtAgg\n\n### Python version\n\n3.9.13\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nLinux package manager","author":{"url":"https://github.com/brckts","@type":"Person","name":"brckts"},"datePublished":"2022-06-01T09:33:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/23173/matplotlib/issues/23173"}
| 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:c16d6f93-2c3e-e857-afa9-ac8b4e723da4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C954:171DD4:71F165:98F65B:6A526D3C |
| html-safe-nonce | 49a3b0f30e25784bc25940d2f642bd1e8f1342a6960d745ccf6143b8f4186df6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTU0OjE3MURENDo3MUYxNjU6OThGNjVCOjZBNTI2RDNDIiwidmlzaXRvcl9pZCI6IjE4NDY2NzExNTQwNTM1NDExODAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2a00243a928477e0b9894a7b4e11c853836895d9ea6e395ad8b60d6820d741c4 |
| hovercard-subject-tag | issue:1255497160 |
| 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/23173/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2a7c28d30d1fc49a025f331d4ca34f92778afe37a803d281b3fb61f5375a3855/matplotlib/matplotlib/issues/23173 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2a7c28d30d1fc49a025f331d4ca34f92778afe37a803d281b3fb61f5375a3855/matplotlib/matplotlib/issues/23173 |
| og:image:alt | Bug summary Adding a clabel to a contour plot of a subfigure results in a traceback. Code for reproduction # Taken from the Contour Demo example delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brckts |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width