{"action":"created","issue":{"url":"https://api.github.com/repos/ipython/ipython/issues/7520","labels_url":"https://api.github.com/repos/ipython/ipython/issues/7520/labels{/name}","comments_url":"https://api.github.com/repos/ipython/ipython/issues/7520/comments","events_url":"https://api.github.com/repos/ipython/ipython/issues/7520/events","html_url":"https://github.com/ipython/ipython/issues/7520","id":54987041,"number":7520,"title":"Cannot use interact with matplotlib figures that are updated in-place","user":{"login":"ketch","id":697763,"avatar_url":"https://avatars.githubusercontent.com/u/697763?v=3","gravatar_id":"","url":"https://api.github.com/users/ketch","html_url":"https://github.com/ketch","followers_url":"https://api.github.com/users/ketch/followers","following_url":"https://api.github.com/users/ketch/following{/other_user}","gists_url":"https://api.github.com/users/ketch/gists{/gist_id}","starred_url":"https://api.github.com/users/ketch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ketch/subscriptions","organizations_url":"https://api.github.com/users/ketch/orgs","repos_url":"https://api.github.com/users/ketch/repos","events_url":"https://api.github.com/users/ketch/events{/privacy}","received_events_url":"https://api.github.com/users/ketch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-21T07:36:56Z","updated_at":"2015-01-21T07:39:39Z","closed_at":null,"body":"In all the examples I can find using interact to produce matplotlib plots in the notebook, the function that is passed to interact generates a new matplotlib Figure.  For instance, \r\n\r\nhttp://nbviewer.ipython.org/github/dsoto/ipython/blob/master/examples/Interactive%20Widgets/Image%20Browser.ipynb\r\n\r\nIf one modifies that example to create a single Figure and Axes beforehand and then just modify what is on the axes for each widget value, it doesn't work; only the widget appears, with no plot.  Here is the modification I'm referring to:\r\n\r\n```python\r\n%matplotlib inline\r\nimport matplotlib.pyplot as plt\r\nfrom IPython.html.widgets import interact\r\nfrom sklearn import datasets\r\ndigits = datasets.load_digits()\r\nfig = plt.figure()\r\nax = fig.add_subplot(111)\r\n\r\ndef browse_images(digits):\r\n    n = len(digits.images)\r\n    def view_image(i):\r\n        ax.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')\r\n        ax.set_title('Training: %s' % digits.target[i])\r\n        plt.show()\r\n        return fig\r\n    interact(view_image, i=(0,n-1))\r\nbrowse_images(digits)\r\n```\r\n\r\nIt often makes more sense to generate the figure and axes beforehand, and modify things in-place.  I would like to be able to do this within interact."},"comment":{"url":"https://api.github.com/repos/ipython/ipython/issues/comments/70796478","html_url":"https://github.com/ipython/ipython/issues/7520#issuecomment-70796478","issue_url":"https://api.github.com/repos/ipython/ipython/issues/7520","id":70796478,"user":{"login":"ketch","id":697763,"avatar_url":"https://avatars.githubusercontent.com/u/697763?v=3","gravatar_id":"","url":"https://api.github.com/users/ketch","html_url":"https://github.com/ketch","followers_url":"https://api.github.com/users/ketch/followers","following_url":"https://api.github.com/users/ketch/following{/other_user}","gists_url":"https://api.github.com/users/ketch/gists{/gist_id}","starred_url":"https://api.github.com/users/ketch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ketch/subscriptions","organizations_url":"https://api.github.com/users/ketch/orgs","repos_url":"https://api.github.com/users/ketch/repos","events_url":"https://api.github.com/users/ketch/events{/privacy}","received_events_url":"https://api.github.com/users/ketch/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T07:39:39Z","updated_at":"2015-01-21T07:39:39Z","body":"Note that matplotlib's `funcanimation` does work with in-place figure updates."}}