How can I open the interactive matplotlib window in IPython notebook?

后端 未结 7 1936
臣服心动
臣服心动 2020-11-30 17:30

I am using IPython with --pylab=inline and would sometimes like to quickly switch to the interactive, zoomable matplotlib GUI for viewing plots (the one that po

7条回答
  •  心在旅途
    2020-11-30 18:09

    I'm using ipython in "jupyter QTConsole" from Anaconda at www.continuum.io/downloads on 5/28/20117.

    Here's an example to flip back and forth between a separate window and an inline plot mode using ipython magic.

    >>> import matplotlib.pyplot as plt
    
    # data to plot
    >>> x1 = [x for x in range(20)]
    
    # Show in separate window
    >>> %matplotlib
    >>> plt.plot(x1)
    >>> plt.close() 
    
    # Show in console window
    >>> %matplotlib inline
    >>> plt.plot(x1)
    >>> plt.close() 
    
    # Show in separate window
    >>> %matplotlib
    >>> plt.plot(x1)
    >>> plt.close() 
    
    # Show in console window
    >>> %matplotlib inline
    >>> plt.plot(x1)
    >>> plt.close() 
    
    # Note: the %matplotlib magic above causes:
    #      plt.plot(...) 
    # to implicitly include a:
    #      plt.show()
    # after the command.
    #
    # (Not sure how to turn off this behavior
    # so that it matches behavior without using %matplotlib magic...)
    # but its ok for interactive work...
    

提交回复
热议问题