Title: Callbacks of draggable artists should check that they have not been removed · Issue #6785 · matplotlib/matplotlib · GitHub
Open Graph Title: Callbacks of draggable artists should check that they have not been removed · Issue #6785 · matplotlib/matplotlib
X Title: Callbacks of draggable artists should check that they have not been removed · Issue #6785 · matplotlib/matplotlib
Description: mpl1.5.1/2.0b2 A minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click: from matplotlib import pyplot as plt fig, ax = plt.subplots() ann = None def cb(event): glob...
Open Graph Description: mpl1.5.1/2.0b2 A minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click: from matplotlib import pyplot as plt fig, ax = plt.s...
X Description: mpl1.5.1/2.0b2 A minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click: from matplotlib import pyplot as plt fig, ax = plt.s...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/6785
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Callbacks of draggable artists should check that they have not been removed","articleBody":"mpl1.5.1/2.0b2\n\nA minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click:\n\n```\nfrom matplotlib import pyplot as plt\n\nfig, ax = plt.subplots()\n\nann = None\n\ndef cb(event):\n global ann\n if event.button == 1:\n if ann:\n ann.remove()\n ann = ax.annotate(\"foo\", (event.xdata, event.ydata))\n fig.canvas.draw()\n if event.button == 3:\n if ann:\n ann.remove()\n ann = None\n fig.canvas.draw()\n\nfig.canvas.mpl_connect(\"button_press_event\", cb)\nplt.show()\n```\n\nIf we want to make the annotation also draggable, we could add `ann.draggable()` after adding it. But then right-clicking to remove the annotation results in\n\n```\nTraceback (most recent call last):\n File \"/usr/lib/python3.5/site-packages/matplotlib/backends/backend_qt5.py\", line 290, in mouseReleaseEvent\n guiEvent=event)\n File \"/usr/lib/python3.5/site-packages/matplotlib/backend_bases.py\", line 1921, in button_release_event\n self.callbacks.process(s, event)\n File \"/usr/lib/python3.5/site-packages/matplotlib/cbook.py\", line 550, in process\n proxy(*args, **kwargs)\n File \"/usr/lib/python3.5/site-packages/matplotlib/cbook.py\", line 417, in __call__\n return mtd(*args, **kwargs)\n File \"/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py\", line 1687, in on_release\n self.finalize_offset()\n File \"/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py\", line 1768, in finalize_offset\n pos_axes_fraction = self.annotation.axes.transAxes.inverted()\nAttributeError: 'NoneType' object has no attribute 'transAxes'\nFatal Python error: Aborted\n```\n\nbasically because the `button_release` callback is called one last time after the annotation has been removed from the axes (and thus `annotation.axes` is `None`).\n\nSo either the draggable artist should check that it is still valid while executing callback code, or it should disconnect itself upon removal (but there may be some weird race conditions?).\n","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2016-07-17T23:48:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/6785/matplotlib/issues/6785"}
| 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:b7df217f-86c4-7a3a-a342-475e550fcf1c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95D0:2D9C09:1E0FD1F:28FE20C:6A54093D |
| html-safe-nonce | c46a57dcc66a77267acfd7c6c841b3009022b085e93b8bac8a3438ac22d0b50f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUQwOjJEOUMwOToxRTBGRDFGOjI4RkUyMEM6NkE1NDA5M0QiLCJ2aXNpdG9yX2lkIjoiNzYxNDAwNTk2NDE0MDk3MjM0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d78e17402fa43f23caddecee7f273e4605b47e51976128b1397e13688393498c |
| hovercard-subject-tag | issue:166002529 |
| 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/6785/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7808c6d1ee90628516a9b409621450a2a9f8b067869ec4b40885ffd3b7056280/matplotlib/matplotlib/issues/6785 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7808c6d1ee90628516a9b409621450a2a9f8b067869ec4b40885ffd3b7056280/matplotlib/matplotlib/issues/6785 |
| og:image:alt | mpl1.5.1/2.0b2 A minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click: from matplotlib import pyplot as plt fig, ax = plt.s... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| 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