{"action":"opened","issue":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6785","repository_url":"https://api.github.com/repos/matplotlib/matplotlib","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6785/labels{/name}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6785/comments","events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/6785/events","html_url":"https://github.com/matplotlib/matplotlib/issues/6785","id":166002529,"number":6785,"title":"Callbacks of draggable artists should check that they have not been removed","user":{"login":"anntzer","id":1322974,"avatar_url":"https://avatars.githubusercontent.com/u/1322974?v=3","gravatar_id":"","url":"https://api.github.com/users/anntzer","html_url":"https://github.com/anntzer","followers_url":"https://api.github.com/users/anntzer/followers","following_url":"https://api.github.com/users/anntzer/following{/other_user}","gists_url":"https://api.github.com/users/anntzer/gists{/gist_id}","starred_url":"https://api.github.com/users/anntzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anntzer/subscriptions","organizations_url":"https://api.github.com/users/anntzer/orgs","repos_url":"https://api.github.com/users/anntzer/repos","events_url":"https://api.github.com/users/anntzer/events{/privacy}","received_events_url":"https://api.github.com/users/anntzer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-17T23:48:12Z","updated_at":"2016-07-17T23:48:12Z","closed_at":null,"body":"mpl1.5.1/2.0b2\r\n\r\nA minimal mpldatacursor-like module, that adds a single annotation wherever the user left-clicks and removes it upon right click:\r\n```\r\nfrom matplotlib import pyplot as plt\r\n\r\nfig, ax = plt.subplots()\r\n\r\nann = None\r\n\r\ndef cb(event):\r\n    global ann\r\n    if event.button == 1:\r\n        if ann:\r\n            ann.remove()\r\n        ann = ax.annotate(\"foo\", (event.xdata, event.ydata))\r\n        fig.canvas.draw()\r\n    if event.button == 3:\r\n        if ann:\r\n            ann.remove()\r\n            ann = None\r\n        fig.canvas.draw()\r\n\r\nfig.canvas.mpl_connect(\"button_press_event\", cb)\r\nplt.show()\r\n```\r\n\r\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\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/backends/backend_qt5.py\", line 290, in mouseReleaseEvent\r\n    guiEvent=event)\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/backend_bases.py\", line 1921, in button_release_event\r\n    self.callbacks.process(s, event)\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/cbook.py\", line 550, in process\r\n    proxy(*args, **kwargs)\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/cbook.py\", line 417, in __call__\r\n    return mtd(*args, **kwargs)\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py\", line 1687, in on_release\r\n    self.finalize_offset()\r\n  File \"/usr/lib/python3.5/site-packages/matplotlib/offsetbox.py\", line 1768, in finalize_offset\r\n    pos_axes_fraction = self.annotation.axes.transAxes.inverted()\r\nAttributeError: 'NoneType' object has no attribute 'transAxes'\r\nFatal Python error: Aborted\r\n```\r\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`).\r\n\r\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?)."}}
{"actor":{"display_login":"anntzer"}}