matplotlib/matplotlib — pull request #3008 by pelson (2014-04-24 13:11:50+00:00)
Title: Nbagg backend

Implements the nbAgg backend for interactive figures in the IPython notebook, using IPython's comm protocol.

@jasongrout's excellent proof of concept ``CommFigure`` in #2524 was used as an initial base (which itself made good use of @mdboom and my own work on the WebAgg backend), but I've removed the ``CommFigure`` concept and have instead plumbed this into a real matplotlib backend.

As a result, using IPython notebook v2.0 I am able to run the following code in the notebook to achieve an interactive figure:

``
import matplotlib
matplotlib.use('nbagg')

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 1000)
plt.plot(x, np.cos(3*x) - np.sin(2*x)**2)
plt.show()
``

I've currently only been able to test this with Firefox 24.4, so any feedback from other browsers would be valuable.

There are a few features I've not added at this point (but would like to do so):

* An event loop
* Support for interactive mode and the ability to "re-show" a figure.
* Better keyboard event integration with IPython notebook (currently pressing the close button destroys all IPython keyboard events, and when the mpl figure has focus, no IPython shortcuts are triggered)
* Remove the hack which identifies which cell contains the output that has just been written (using the unique ID defined at show time of a figure).
* Adding ``%matplotlib nbagg`` (in IPython itself)