{"action":"created","issue":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/3706","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/3706/labels{/name}","comments_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/3706/comments","events_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/3706/events","html_url":"https://github.com/matplotlib/matplotlib/issues/3706","id":46582492,"number":3706,"title":"Data draws on top of legend.","user":{"login":"Redoubts","id":2435101,"avatar_url":"https://avatars.githubusercontent.com/u/2435101?v=3","gravatar_id":"","url":"https://api.github.com/users/Redoubts","html_url":"https://github.com/Redoubts","followers_url":"https://api.github.com/users/Redoubts/followers","following_url":"https://api.github.com/users/Redoubts/following{/other_user}","gists_url":"https://api.github.com/users/Redoubts/gists{/gist_id}","starred_url":"https://api.github.com/users/Redoubts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Redoubts/subscriptions","organizations_url":"https://api.github.com/users/Redoubts/orgs","repos_url":"https://api.github.com/users/Redoubts/repos","events_url":"https://api.github.com/users/Redoubts/events{/privacy}","received_events_url":"https://api.github.com/users/Redoubts/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/matplotlib/matplotlib/labels/can't%20fix","name":"can't fix","color":"d4c5f9"},{"url":"https://api.github.com/repos/matplotlib/matplotlib/labels/confirmed%20bug","name":"confirmed bug","color":"444444"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/15","html_url":"https://github.com/matplotlib/matplotlib/milestones/unassigned","labels_url":"https://api.github.com/repos/matplotlib/matplotlib/milestones/15/labels","id":719140,"number":15,"title":"unassigned","description":null,"creator":{"login":"tacaswell","id":199813,"avatar_url":"https://avatars.githubusercontent.com/u/199813?v=3","gravatar_id":"","url":"https://api.github.com/users/tacaswell","html_url":"https://github.com/tacaswell","followers_url":"https://api.github.com/users/tacaswell/followers","following_url":"https://api.github.com/users/tacaswell/following{/other_user}","gists_url":"https://api.github.com/users/tacaswell/gists{/gist_id}","starred_url":"https://api.github.com/users/tacaswell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tacaswell/subscriptions","organizations_url":"https://api.github.com/users/tacaswell/orgs","repos_url":"https://api.github.com/users/tacaswell/repos","events_url":"https://api.github.com/users/tacaswell/events{/privacy}","received_events_url":"https://api.github.com/users/tacaswell/received_events","type":"User","site_admin":false},"open_issues":96,"closed_issues":79,"state":"open","created_at":"2014-07-12T20:04:20Z","updated_at":"2015-12-01T16:10:57Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2014-10-23T02:28:54Z","updated_at":"2015-12-13T14:41:23Z","closed_at":null,"body":"I would expect the legend to draw on top of everything, but it seems to be obscured by plotted data from time to time.\r\n\r\n![figure_2](https://cloud.githubusercontent.com/assets/2435101/4747407/059289c4-5a5c-11e4-846f-28327a359258.png)\r\n\r\nThe unfortunate above example keeps happening for me on OS X 10.10.\r\n```\r\nPython 2.7.6 (default, Sep  9 2014, 15:04:36) \r\nIPython 2.3.0 -- An enhanced Interactive Python.\r\n\r\nUsing matplotlib backend: MacOSX\r\nIn [2]: numpy.__version__\r\nOut[2]: '1.9.0'\r\n\r\nIn [3]: scipy.__version__\r\nOut[3]: '0.14.0'\r\n\r\nIn [4]: matplotlib.__version__\r\nOut[4]: '1.4.1'\r\n```"},"comment":{"url":"https://api.github.com/repos/matplotlib/matplotlib/issues/comments/164265176","html_url":"https://github.com/matplotlib/matplotlib/issues/3706#issuecomment-164265176","issue_url":"https://api.github.com/repos/matplotlib/matplotlib/issues/3706","id":164265176,"user":{"login":"soupault","id":1315589,"avatar_url":"https://avatars.githubusercontent.com/u/1315589?v=3","gravatar_id":"","url":"https://api.github.com/users/soupault","html_url":"https://github.com/soupault","followers_url":"https://api.github.com/users/soupault/followers","following_url":"https://api.github.com/users/soupault/following{/other_user}","gists_url":"https://api.github.com/users/soupault/gists{/gist_id}","starred_url":"https://api.github.com/users/soupault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soupault/subscriptions","organizations_url":"https://api.github.com/users/soupault/orgs","repos_url":"https://api.github.com/users/soupault/repos","events_url":"https://api.github.com/users/soupault/events{/privacy}","received_events_url":"https://api.github.com/users/soupault/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T14:41:22Z","updated_at":"2015-12-13T14:41:22Z","body":"@WeatherGod ok, thanks! I suppose this should be reworked...\r\n\r\nAs a temporary workaround I'm using following approach:\r\n\r\nI've written a routine which takes `a list of axes` as input and returns united `handles` and `labels`. Then, these vectors has to be used on **last** initialized axes for current figure.\r\n\r\nFor example, you have\r\n   \r\n    fig, axes = plt.subplots()\r\n    axes_r = axes.twinx()\r\n\r\n    # ... HERE YOU PLOT A LOT OF THING ON BOTH axes AND axes_r\r\n    \r\n    def unite_legends(axes):\r\n        h, l = [], []\r\n        for ax in axes:\r\n            tmp = ax.get_legend_handles_labels()\r\n            h.extend(tmp[0])\r\n            l.extend(tmp[1])\r\n        return h, l\r\n\r\n    handles, labels = unite_legends([axes, axes_r])\r\n    # ... HERE YOU SHOULD USE LAST axes INITIALIZED. IN THIS CASE IT'S axes_r\r\n    axes_r.legend(handles, labels, loc='center')\r\n\r\nFor the example of @Redoubts it returns:\r\n![figure_1](https://cloud.githubusercontent.com/assets/1315589/11767500/b47c595e-a1c0-11e5-8154-1aa4e6136ffd.png)\r\n\r\nP.S. Actually, I always work with `axes`-array, even if it's 1x1, so my oftenly used `unite_legends` is a bit more complex."}}