[IPython-dev] How IPython achieve embedding of matplotlib figure ?

Fernando Perez fperez.net@gmail....
Fri Oct 28 18:40:13 CDT 2011


On Mon, Oct 24, 2011 at 4:51 AM, Guillaume Pichard
<guillaume.pichard@sogeti.com> wrote:
>
> What I would like to know is how IPython achieve this feature and how
> can I replicate it with my own Python code ? I saw that there are
> using displayhook, but how can IPython catch output from matplotlib
> functions ?
>
> I would be greatful if you could give me some pointers on how to do
> this feature.

We have a custom matplotlib backend that ships the figures encoded as
data in a JSON payload over ZeroMQ.  Then, each client (Qt console,
Web notebook) is responsible for decoding these messages and deciding
how to display this output.  The relevant pieces of server-side code
are:

https://github.com/ipython/ipython/blob/master/IPython/zmq/pylab/backend_inline.py

https://github.com/ipython/ipython/blob/master/IPython/core/displaypub.py

And each client has its own display logic, here's the Qt client
capable of displaying png/svg images:

https://github.com/ipython/ipython/blob/master/IPython/frontend/qt/console/rich_ipython_widget.py

I hope this helps...

Best,

f


More information about the IPython-dev mailing list