Title: Reusing cleared figure with suptitle and constrained layout raises an exception · Issue #11115 · matplotlib/matplotlib · GitHub
Open Graph Title: Reusing cleared figure with suptitle and constrained layout raises an exception · Issue #11115 · matplotlib/matplotlib
X Title: Reusing cleared figure with suptitle and constrained layout raises an exception · Issue #11115 · matplotlib/matplotlib
Description: Bug report Bug summary Suptitle and constrained layout raises an exception whenclearing-and-reusing an existing figure. Originally noticed in #11035 . Attn @jklymak aka. our layout manager expert Code for reproduction import matplotlib.p...
Open Graph Description: Bug report Bug summary Suptitle and constrained layout raises an exception whenclearing-and-reusing an existing figure. Originally noticed in #11035 . Attn @jklymak aka. our layout manager expert C...
X Description: Bug report Bug summary Suptitle and constrained layout raises an exception whenclearing-and-reusing an existing figure. Originally noticed in #11035 . Attn @jklymak aka. our layout manager expert C...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11115
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reusing cleared figure with suptitle and constrained layout raises an exception","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nSuptitle and constrained layout raises an exception whenclearing-and-reusing an existing figure. Originally noticed in #11035 .\r\n\r\nAttn @jklymak aka. our layout manager expert\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\n# Use-case: at the beginning of a session\r\nfig, ax = plt.subplots(constrained_layout=True, num='boo')\r\nfig.suptitle(\"Dummy\")\r\nplt.show()\r\n\r\n# Use-case: later in the same session\r\nfig, ax = plt.subplots(constrained_layout=True, num='boo', clear=True)\r\nax.plot(range(30))\r\nplt.show()\r\n\r\n#=\u003e boom, AttributeError\r\n```\r\n\r\n**Actual outcome**\r\n\r\n```python\r\n---------------------------------------------------------------------------\r\nAttributeError Traceback (most recent call last)\r\n\u003cipython-input-6-a852cdf04f60\u003e in \u003cmodule\u003e()\r\n 5 plt.show()\r\n 6 \r\n----\u003e 7 fig, ax = plt.subplots(constrained_layout=True, num='boo', clear=True)\r\n 8 ax.plot(range(30))\r\n 9 plt.show()\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)\r\n 1196 subplot\r\n 1197 \"\"\"\r\n-\u003e 1198 fig = figure(**fig_kw)\r\n 1199 axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,\r\n 1200 squeeze=squeeze, subplot_kw=subplot_kw,\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs)\r\n 574 \r\n 575 if clear:\r\n--\u003e 576 figManager.canvas.figure.clear()\r\n 577 \r\n 578 return figManager.canvas.figure\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in clear(self, keep_observers)\r\n 1434 Clear the figure -- synonym for :meth:`clf`.\r\n 1435 \"\"\"\r\n-\u003e 1436 self.clf(keep_observers=keep_observers)\r\n 1437 \r\n 1438 @allow_rasterization\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py in clf(self, keep_observers)\r\n 1427 self._suptitle = None\r\n 1428 if self.get_constrained_layout():\r\n-\u003e 1429 layoutbox.nonetree(self._layoutbox)\r\n 1430 self.stale = True\r\n 1431 \r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/_layoutbox.py in nonetree(lb)\r\n 672 # Clear the solver. Hopefully this garbage collects.\r\n 673 lb.solver.reset()\r\n--\u003e 674 nonechildren(lb)\r\n 675 else:\r\n 676 nonetree(lb.parent)\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/_layoutbox.py in nonechildren(lb)\r\n 679 def nonechildren(lb):\r\n 680 for child in lb.children:\r\n--\u003e 681 nonechildren(child)\r\n 682 lb.artist._layoutbox = None\r\n 683 lb = None\r\n\r\n~/anaconda3/lib/python3.6/site-packages/matplotlib/_layoutbox.py in nonechildren(lb)\r\n 680 for child in lb.children:\r\n 681 nonechildren(child)\r\n--\u003e 682 lb.artist._layoutbox = None\r\n 683 lb = None\r\n 684 \r\n\r\nAttributeError: 'NoneType' object has no attribute '_layoutbox'\r\n\r\n```\r\n\r\n**Expected outcome**\r\n\r\nNo Exception, but a clear Figure named 'boo'.\r\n\r\n\r\n**Matplotlib version**\r\n * Operating system: Fedora 27\r\n * Matplotlib version: master ('2.2.2.post856+g506520f30') and 2.2.2\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): Qt5Agg\r\n * Python version: 3.6 (Anaconda)\r\n\r\n**Being there**\r\n\r\nSome test snippet to put in `test_constrainedlayout.py`\r\n```python\r\ndef test_constrained_layout23():\r\n '''\r\n Comment in #11035: suptitle used to cause an exception when\r\n reusing a figure w/ CL with ``clear=True``.\r\n '''\r\n\r\n for i in range(2):\r\n fig, ax = plt.subplots(num=\"123\", constrained_layout=True, clear=True)\r\n fig.suptitle(f\"Suptitle {i}\".format(i))\r\n\r\n```\r\n","author":{"url":"https://github.com/afvincent","@type":"Person","name":"afvincent"},"datePublished":"2018-04-24T04:25:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/11115/matplotlib/issues/11115"}
| 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:524938d8-b295-e997-8eec-651a7f986856 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5F2:D635E:1AEBBFB:270C19B:6A56344D |
| html-safe-nonce | 5424c1741e42b2463289e698ae3ce2c1589d1a9353f2a25766a74614ab4900ad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUYyOkQ2MzVFOjFBRUJCRkI6MjcwQzE5Qjo2QTU2MzQ0RCIsInZpc2l0b3JfaWQiOiI3MDE5ODA1MjkxODAzMTk0NDQ1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9ad4889bcf52227aff84959779a47a1b82124ef4900fdfa5019a6bfa2a56f6b2 |
| hovercard-subject-tag | issue:317065946 |
| 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/11115/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7174d9aca747fe3e682651d4742d44605adf47c949916a6b8705476f841cb96d/matplotlib/matplotlib/issues/11115 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7174d9aca747fe3e682651d4742d44605adf47c949916a6b8705476f841cb96d/matplotlib/matplotlib/issues/11115 |
| og:image:alt | Bug report Bug summary Suptitle and constrained layout raises an exception whenclearing-and-reusing an existing figure. Originally noticed in #11035 . Attn @jklymak aka. our layout manager expert C... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | afvincent |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9d78ea552aac0685ca5f006d44f88166cbbf3bb96843f8da0c5a2c0b9908430b |
| 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 | 423b2fb76ac2b90de5ab599b7a76a0d2b2c83f24 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width