Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

python - ipython --pylab vs ipython

What does ipython --pylab exactly do?

Is ipython --pylab exactly equivalent to:

 > ipython
 > from pylab import *

If not, what are the differences?

Say I launch IPython without the --pylab arguments, how can I bring it to the same state as if I had started it with --pylab?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

--pylab[=option] is almost technically equivalent to %pylab option as the difference that you cannot un-pylab a --pylab kernel, but you can restart a %pylab kernel.

%pylab is a little more that just from pylab import * (see %pylab?for a longer explanation), but in short yes it imports a lot of things, but it also hooks event loops (qt, wx, osx...) and set-up some display hooks for matplotlib (the things that magically allow you to get inline graph). Setting the display-hook is closer to something like sympy.init_printing() if you wonder.

Note that starting at IPython 1.0 we recommend not to use --pylab or %pylab (unless you know exactly the implication). We provide %matplotlib that only init the display hook. %pylab will warn you if it replaced a few object in current namespace, and which ones. This is useful especially for functions like sum which do not have the same behavior the behavior with and without pylab and leads to subtle bugs.

We consider now that --pylab was a mistake, but that it was still really usefull at the beginning of IPython. We all know that Explicit is better than implicit so if you can advise people not to use %pylab we would appreciate it, to one day get rid of it.

Extract from %pylab help that give only the import part of pylab:

%pylab makes the following imports::

import numpy
import matplotlib
from matplotlib import pylab, mlab, pyplot
np = numpy
plt = pyplot

from IPython.display import display
from IPython.core.pylabtools import figsize, getfigs

from pylab import *
from numpy import *

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...