ipython --pylab vs ipython

前端 未结 3 1255
醉酒成梦
醉酒成梦 2020-12-14 04:41

What does ipython --pylab exactly do?

Is ipython --pylab exactly equivalent to:

 > ipython
 > from         


        
相关标签:
3条回答
  • 2020-12-14 05:06

    One noticeable difference besides the imports is the interactive plotting, which you can enable dynamically with:

    import matplotlib
    matplotlib.rcParams['interactive'] = True
    
    0 讨论(0)
  • 2020-12-14 05:16

    I think the --pylab option on the command line is equivalent to using the %pylab magic. At least that is how I have used it. That also gives you the opportunity to choose plotting backend, i.e. %pylab inline, %pylab qt, etc.

    0 讨论(0)
  • 2020-12-14 05:24

    --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 *
    
    0 讨论(0)
提交回复
热议问题