Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

[WIP] Inline matplotlib #7

Closed
wants to merge 1 commit into from
Closed

[WIP] Inline matplotlib #7

wants to merge 1 commit into from

Conversation

rgbkrk
Copy link
Member

@rgbkrk rgbkrk commented Sep 6, 2014

Opinionated PR about inlining matplotlib by default.

I advocate for this so that people don't have to either

  • select a backend
  • run %matplotlib inline

/cc @Carreau @minrk - lend me your opinions

@takluyver
Copy link
Member

From in-person discussion:

  1. I'm in favour of making inline plots the default, see Make matplotlib inline backend the default when loaded in IPython kernel ipython/ipython#6424.
  2. The --matplotlib flag will break with IPython 3, and I think config will be needed to do the same thing.
  3. Forcing matplotlib to load will slow down kernel start
  4. The 'notebook' image probably shouldn't try to load matplotlib, because it may not be installed. Not sure what happens in this case.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 6, 2014

Addressed the fourth point just now by only introducing --matplotlib inline on the ipython/scipyserver image.

@tacaswell
Copy link

@takluyver Can you elaborate on point 2? Breaking --matplotlib seems like a bad thing to do...

@Carreau
Copy link
Member

Carreau commented Sep 6, 2014

--matplotlib is a kernel flag, not a frontend flag. it does not make sens with julia kernel, ruby kernel, bash, ocaml, haskel, ...etc. keeping it break all theses kernel, so it is going to be droped.

@tacaswell
Copy link

ah, ok. If I understand the distinctions, it will still be there for the console version of ipython (that is at bash ipython --matplotlib will still work as expected)?

Sorry, I am not as up on all of the terminology/naming conventions as I should be.

@Carreau
Copy link
Member

Carreau commented Sep 6, 2014

Yes, --matplotlib will still exist, just the notebook server will not accept the argument. ie:

$ ipython --matplotlib // ok
$ ipython qtconsole --matplotlib // no, qtconsole can connect to julia
$ ipython notebook --matplotlib // no, notebook can run haskell

setting c.IPKernel.matplotlib will work, as it targets only IPython kernel.
actually you will even be allowd to have notebook with some --matplotlib kernel and soem without --matplotlib if you like.

Sorry, I am not as up on all of the terminology/naming conventions as I should be.

No problem, we can't ask everyone to follow everything.

@takluyver
Copy link
Member

I think it will actually still work for the qtconsole as well, but I wouldn't rely on that always being the case.

@Carreau
Copy link
Member

Carreau commented Sep 6, 2014

I think it will actually still work for the qtconsole as well, but I wouldn't rely on that always being the case.

Yep it was more a comment on how it should be that how it is :-)

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 8, 2014

For the sake of the current release of IPython, I'll advocate for this on the scipyserver image.

@minrk
Copy link
Member

minrk commented Sep 8, 2014

Since --matplotlib can slow down startup for every kernel, especially on slow-IO VMs, making inline the default matplotlib backend (in matplotlibrc) might be a lighter touch that solves the same problem.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

Setting up a non-root user is causing some weird issues. The kernel keeps restarting.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

13:42:32 (matplotlib=) rgbkrk@metallic ~/docker-notebook/scipyserver$ sudo docker run -it -p 443:8888 -v /home/rgbkrk/certs/crt.all:/certs/crt.all -e PEM_FILE=/certs/crt.all -e PASSWORD=ReallyGreatPassword ipython/scipyserver
2014-09-10 13:42:39.766 [NotebookApp] Created profile dir: '/home/ipynb/.ipython/profile_default'
2014-09-10 13:42:39.770 [NotebookApp] Using MathJax from CDN: https://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-09-10 13:42:39.784 [NotebookApp] Serving notebooks from local directory: /home/ipynb
2014-09-10 13:42:39.784 [NotebookApp] 0 active kernels
2014-09-10 13:42:39.784 [NotebookApp] The IPython Notebook is running at: https://[all ip addresses on your system]:8888/
2014-09-10 13:42:39.784 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
INFO:tornado.access:302 GET / (99.57.20.144) 1.06ms
INFO:tornado.access:302 POST /login?next=%2F (99.57.20.144) 0.77ms
INFO:tornado.access:302 GET / (99.57.20.144) 0.50ms
2014-09-10 13:42:51.362 [NotebookApp] Creating new notebook in /
2014-09-10 13:42:51.363 [NotebookApp] Writing notebook-signing key to /home/ipynb/.ipython/profile_default/security/notebook_secret
2014-09-10 13:42:52.201 [NotebookApp] Kernel started: 384041a7-b254-474d-b94a-dec4877b02b4
2014-09-10 13:42:55.202 [NotebookApp] KernelRestarter: restarting kernel (1/5)
WARNING:root:kernel 384041a7-b254-474d-b94a-dec4877b02b4 restarted
2014-09-10 13:42:58.207 [NotebookApp] KernelRestarter: restarting kernel (2/5)
WARNING:root:kernel 384041a7-b254-474d-b94a-dec4877b02b4 restarted
2014-09-10 13:43:01.212 [NotebookApp] KernelRestarter: restarting kernel (3/5)
WARNING:root:kernel 384041a7-b254-474d-b94a-dec4877b02b4 restarted
2014-09-10 13:43:04.217 [NotebookApp] KernelRestarter: restarting kernel (4/5)
WARNING:root:kernel 384041a7-b254-474d-b94a-dec4877b02b4 restarted
^C2014-09-10 13:43:06.892 [NotebookApp] interrupted
Serving notebooks from local directory: /home/ipynb
1 active kernels
The IPython Notebook is running at: https://[all ip addresses on your system]:8888/
Shutdown this notebook server (y/[n])? 2014-09-10 13:43:07.220 [NotebookApp] WARNING | KernelRestarter: restart failed
2014-09-10 13:43:07.220 [NotebookApp] WARNING | Kernel 384041a7-b254-474d-b94a-dec4877b02b4 died, removing from map.
ERROR:root:kernel 384041a7-b254-474d-b94a-dec4877b02b4 restarted failed!
^C2014-09-10 13:43:10.054 [NotebookApp] CRITICAL | received signal 2, stopping
2014-09-10 13:43:10.055 [NotebookApp] Shutting down kernels

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

Looks like the kernel restarting is happening because I'm running exec ipython notebook...

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

With that out of the way, it appears that matplotlib doesn't like the current $DISPLAY variable.

Off to the zoo, I'll touch this up again later.

@ssanderson
Copy link

@rgbkrk do you know why execing the notebook causes the kernels to get restarted forever? I ran into the exact same issue when trying to set a raw ipython notebook command for CMD or ENTRYPOINT (which ultimately translates into those commands being exec'ed I think). I fixed the issue to by restructuring my Dockerfile to call a script as its CMD the same way you do, but I haven't yet figured out why the alternative calling method makes ipython unhappy.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

Not sure what is causing that. I ended up having to shelve that earlier to
spend family time.

Without the exec, you can't ctrl-c to kill the running notebook server.

On Wednesday, September 10, 2014, Scott Sanderson [email protected]
wrote:

@rgbkrk https://github.com/rgbkrk do you know why execing the notebook
causes the kernels to get restarted forever? I ran into the exact same
issue when trying to set a raw ipython notebook command for CMD or
ENTRYPOINT (which ultimately translates into those commands being exec'ed
I think). I fixed the issue to by restructuring my Dockerfile to use call a
script as its CMD the same way you do, but I haven't yet figured out why
the alternative calling method makes ipython unhappy.


Reply to this email directly or view it on GitHub
#7 (comment).

Kyle Kelley (@rgbkrk https://twitter.com/rgbkrk; http://lambdaops.com)

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 10, 2014

Forgot to mention, exec as root works just fine. This just affects introducing a default user in the container and running the notebook on top of that.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 12, 2014

Trying out nbAgg out for the first time:

screen shot 2014-09-11 at 9 33 22 pm

What should the default matplotlibrc hold?

@tacaswell
Copy link

As a side note, nbagg is broken in 1.4.0 in py3, there is a PR that fixes it (matplotlib/matplotlib#3464) and we are planning to do 1.4.1 at the end of the month.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 12, 2014

@tacaswell That's too bad.

On a side note, I'm noticing that nbAgg takes us back to the whole figure, ..., plot workflow. It's explicit, but then doesn't play well with default pandas workflow, e.g. df.plot().

What backend should I setup? I'm happy to accept a PR for an "opinionated best" matplotlibrc.

%matplotlib inline, pylabtools

@rgbkrk rgbkrk changed the title Inline matplotlib [WIP] Inline matplotlib Sep 12, 2014
@tacaswell
Copy link

I am not sure why nbagg requires an explicit call to show (cc @pelson, @mdboom). I suspect that if you just throw a plt.show() after the pandas calls it will work.

@takluyver
Copy link
Member

I think activating the inline backend sets up some hooks that run after a cell has executed, to grab the current figure and display it. It's probably possible to do something similar in nbagg, if mpl likes that model.

@tacaswell
Copy link

Do the hooks live in the ipython or mpl source tree?

@takluyver
Copy link
Member

IPython. See IPython.kernel.zmq.pylab.backend_inline.flush_figures and IPython.core.pylabtools.configure_inline_support.

@rgbkrk
Copy link
Member Author

rgbkrk commented Sep 12, 2014

If those hooks get brought in to matplotlib itself, could this become as simple as setting the matplotlibrc backend to inline?

backend: inline

@Carreau
Copy link
Member

Carreau commented Sep 12, 2014

That would be sweet!
It would mean no more use of %matplotlib inline and just pure python !?

Envoyé de mon iPhone

Le 12 sept. 2014 à 21:07, Kyle Kelley [email protected] a écrit :

If those hooks get brought in to matplotlib itself, could this become as simple as setting the matplotlibrc backend to inline?

backend: inline

Reply to this email directly or view it on GitHub.

@tacaswell
Copy link

Looking at this very quickly, I think that flush_figures can be generalized a bit and move over to mpl, but I don't think the hook-registration should.

cc @mdboom This might be folding into the is_interactive work.

@rgbkrk
Copy link
Member Author

rgbkrk commented Dec 1, 2014

Closing until we figure out the right way to do the inlining automagically with matplotlib.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants