Title: [Bug]: Artist.remove() isn't fully removing it from figure · Issue #25572 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Artist.remove() isn't fully removing it from figure · Issue #25572 · matplotlib/matplotlib
X Title: [Bug]: Artist.remove() isn't fully removing it from figure · Issue #25572 · matplotlib/matplotlib
Description: Bug summary I am trying to remove some artists (RadioButtons and CheckButtons) while keeping some others (axes with images), before exporting a figure to disk, and am running into this error: AttributeError: 'NoneType' object has no attr...
Open Graph Description: Bug summary I am trying to remove some artists (RadioButtons and CheckButtons) while keeping some others (axes with images), before exporting a figure to disk, and am running into this error: Attri...
X Description: Bug summary I am trying to remove some artists (RadioButtons and CheckButtons) while keeping some others (axes with images), before exporting a figure to disk, and am running into this error: Attri...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/25572
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Artist.remove() isn't fully removing it from figure","articleBody":"### Bug summary\n\nI am trying to remove some artists (`RadioButtons` and `CheckButtons`) while keeping some others (axes with images), before exporting a figure to disk, and am running into this error:\r\n`AttributeError: 'NoneType' object has no attribute 'canvas'`\r\n\r\nas MPL is trying to check if canvas for RadioButton has changed, although that RadioButton should not part of the equation at all as it was removed prior to trying to `.savefig()`\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\n\r\nfrom matplotlib.widgets import RadioButtons\r\n\r\nfig, ax = plt.subplots(1, 1)\r\n\r\nradio = RadioButtons(ax, ['1', '2'], 0)\r\n\r\nradio.ax.remove()\r\n\r\nfig.savefig('~/Downloads/saved_after_artist_remove.png')\n```\n\n\n### Actual outcome\n\n```shell\r\nTraceback (most recent call last):\r\n File \"/Users/Reddy/dev/visualqc/visualqc/tests/artist_remove.py\", line 12, in \u003cmodule\u003e\r\n fig.savefig('~/Downloads/saved_after_artist_remove.png')\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/figure.py\", line 3343, in savefig\r\n self.canvas.print_figure(fname, **kwargs)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backend_bases.py\", line 2366, in print_figure\r\n result = print_method(\r\n ^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backend_bases.py\", line 2232, in \u003clambda\u003e\r\n print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(\r\n ^^^^^\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py\", line 509, in print_png\r\n self._print_pil(filename_or_obj, \"png\", pil_kwargs, metadata)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py\", line 457, in _print_pil\r\n FigureCanvasAgg.draw(self)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backends/backend_agg.py\", line 400, in draw\r\n self.figure.draw(self.renderer)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/artist.py\", line 95, in draw_wrapper\r\n result = draw(artist, renderer, *args, **kwargs)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/artist.py\", line 72, in draw_wrapper\r\n return draw(artist, renderer)\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/figure.py\", line 3150, in draw\r\n DrawEvent(\"draw_event\", self.canvas, renderer)._process()\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/backend_bases.py\", line 1263, in _process\r\n self.canvas.callbacks.process(self.name, self)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/cbook/__init__.py\", line 309, in process\r\n self.exception_handler(exc)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/cbook/__init__.py\", line 96, in _exception_printer\r\n raise exc\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/cbook/__init__.py\", line 304, in process\r\n func(*args, **kwargs)\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/widgets.py\", line 1719, in _clear\r\n if self.ignore(event) or self._changed_canvas():\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/usr/local/lib/python3.11/site-packages/matplotlib/widgets.py\", line 107, in _changed_canvas\r\n return self.canvas is not self.ax.figure.canvas\r\n ^^^^^^^^^^^^^^^^^^^^^\r\nAttributeError: 'NoneType' object has no attribute 'canvas'\r\n```\n\n### Expected outcome\n\nsmooth export with no error\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nmacOS 13\n\n### Matplotlib Version\n\n3.7.1\n\n### Matplotlib Backend\n\nTkAgg\n\n### Python version\n\n3.11\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/raamana","@type":"Person","name":"raamana"},"datePublished":"2023-03-29T18:54:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/25572/matplotlib/issues/25572"}
| 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:627fb332-acd5-bfc8-e4f8-630a7bfb83c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B860:2D56E3:E0374F:12B7EAB:6A53300C |
| html-safe-nonce | c4b806daf471f45ee50aad2b4c34acfe4995d094260ee09168e79c7d16bb278c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODYwOjJENTZFMzpFMDM3NEY6MTJCN0VBQjo2QTUzMzAwQyIsInZpc2l0b3JfaWQiOiI4MjU2MzYyMDc2MDg5NTYxMTAwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9f510881e99c1d7c15d150154af4b978d5d2a1240af286bfa16cfa1a3a0275f1 |
| hovercard-subject-tag | issue:1646346546 |
| 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/25572/issue_layout |
| twitter:image | https://opengraph.githubassets.com/baf43ef252eb440de1580a5b4b37e22190ce077ba29921932165dc29217475df/matplotlib/matplotlib/issues/25572 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/baf43ef252eb440de1580a5b4b37e22190ce077ba29921932165dc29217475df/matplotlib/matplotlib/issues/25572 |
| og:image:alt | Bug summary I am trying to remove some artists (RadioButtons and CheckButtons) while keeping some others (axes with images), before exporting a figure to disk, and am running into this error: Attri... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | raamana |
| 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