[IPython-dev] rant: "%matplotlib inline"

Fernando Perez fperez.net at gmail.com
Fri Jul 3 23:30:22 EDT 2015


On Fri, Jul 3, 2015 at 7:54 PM, William Stein <wstein at gmail.com> wrote:

> What do you think the "principle of least surprise" would dictate
> should happen if you install matplotlib, then copy an example from [1]
> (say) into a new IPython notebook in Python mode?
>
>     [ ] 1. It works
>
>     [ ] 2. It silently fails (the current behavior in IPython notebook).
>
> I'm guessing: pretty much everybody wants 1, but since the kernel
> doesn't know if individual commands are coming from a terminal, native
> UI, web browser, or what, then we have 2.    Is the longterm plan to
> enhance the kernel spec to handle the above situation?
>
> Other systems don't have this problem because one can only interact
> with the kernel from either a terminal or a UI, but not both at once.
>

This summarizes both the expectation and the reason why we have the problem
very well, thanks!

Here's a possible path forward: when we start a kernel, we record what
client started it (honestly I'm not up to speed with the details of the
protocol, it's possible we already do this).

While this doesn't change the fact that a kernel might have multiple
connections later on, at least we can assume that the initiating client is
the most likely one making the key decisions, and in the vast majority of
real-world cases will be the only one in control.

Using this information, we can then put in an import hook for matplotlib,
that would effectively trigger a default call to

%matplotlib notebook

in the notebook

%matplotlib inline

in the Qt console

and

%matplotlib

in the terminal

when "import matplotlib" was called.


Now, users would still need to explicitly call %matplotlib to switch
backends at runtime or make non-default selections, but it would lower the
amount of extra knowledge needed.  Code copied from examples like the one
you point above would "just work", thus improving our marks re. the
principle of least surprise...

Thoughts on this proposal?  Would be good if people hash this out next week
at Scipy with the MPL team...

Cheers

f

-- 
Fernando Perez (@fperez_org; http://fperez.org)
fperez.net-at-gmail: mailing lists only (I ignore this when swamped!)
fernando.perez-at-berkeley: contact me here for any direct mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20150703/7810e7f3/attachment.html>


More information about the IPython-dev mailing list