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

后端 未结 7 1873
臣服心动
臣服心动 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:28

    Starting with matplotlib 1.4.0 there is now an an interactive backend for use in the notebook

    %matplotlib notebook
    

    There are a few version of IPython which do not have that alias registered, the fall back is:

    %matplotlib nbagg
    

    If that does not work update you IPython.

    To play with this, goto tmpnb.org

    and paste

    %matplotlib notebook
    
    import pandas as pd
    import numpy as np
    import matplotlib
    
    from matplotlib import pyplot as plt
    import seaborn as sns
    
    ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
    ts = ts.cumsum()
    
    df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
                      columns=['A', 'B', 'C', 'D'])
    df = df.cumsum()
    df.plot(); plt.legend(loc='best')    
    

    into a code cell (or just modify the existing python demo notebook)

    0 讨论(0)
提交回复
热议问题