[英]ipython --pylab vs ipython
What does ipython --pylab
exactly do? ipython --pylab
到底做了什么?
Is ipython --pylab
exactly equivalent to: ipython --pylab
完全相同于:
> 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
? 假设我在没有
--pylab
参数的情况下启动IPython,我怎样才能将它带到与使用 --pylab
启动它相同的状态?
--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[=option]
几乎在技术上等同于%pylab option
,因为你不能解密--pylab
内核,但你可以重启%pylab
内核。
%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). %pylab
只是from pylab import *
(请参阅%pylab?
以获得更长的解释),但简而言之是它导入很多东西,但它也挂钩了事件循环(qt,wx,osx ......)并为matplotlib设置一些显示挂钩(神奇地允许你获取内联图的东西)。 Setting the display-hook is closer to something like sympy.init_printing()
if you wonder. 如果你想知道,设置display-hook更接近于
sympy.init_printing()
。
Note that starting at IPython 1.0 we recommend not to use --pylab
or %pylab
(unless you know exactly the implication). 请注意,从IPython 1.0开始,我们建议不要使用
--pylab
或%pylab
(除非您完全了解其含义)。 We provide %matplotlib
that only init the display hook. 我们提供
%matplotlib
只启动显示挂钩。 %pylab
will warn you if it replaced a few object in current namespace, and which ones. %pylab
会警告你它是否替换了当前命名空间中的一些对象,以及哪些对象。 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. 这对于诸如
sum
这样的函数是有用的,它们与具有和不具有pylab的行为不具有相同的行为并且导致细微的错误。
We consider now that --pylab
was a mistake, but that it was still really usefull at the beginning of IPython. 我们现在考虑
--pylab
是一个错误,但它在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. 我们都知道
Explicit is better than implicit
所以如果你可以建议人们不要使用%pylab
我们会很感激它,有朝一日可以摆脱它。
Extract from %pylab help that give only the import part of pylab: 从%pylab帮助中提取,只给出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 *
One noticeable difference besides the imports is the interactive plotting, which you can enable dynamically with: 除了导入之外,还有一个明显的区别是交互式绘图,您可以使用以下方式动态启用:
import matplotlib
matplotlib.rcParams['interactive'] = True
I think the --pylab
option on the command line is equivalent to using the %pylab
magic. 我认为命令行上的
--pylab
选项相当于使用%pylab
魔术。 At least that is how I have used it. 至少这就是我如何使用它。 That also gives you the opportunity to choose plotting backend, ie
%pylab inline
, %pylab qt
, etc. 这也让你有机会选择绘制后端,即
%pylab inline
, %pylab qt
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.