Search code examples
pythonpandasmatplotlibipythoninteractive

Pandas plotting in Windows terminal


I have a simple pandas data frame. Trying to plot from the Windows 10 terminal session of IPython gives me this:

In [4]: df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]})

In [5]: df
Out[5]:
   X  Y
0  0  1
1  2  3
2  4  5
3  6  7
4  8  9

In [6]: df.plot(kind='line')
Out[6]: <matplotlib.axes._subplots.AxesSubplot at 0x26c4d366940>

In [7]:

I can not see any plot. Is there something I'm doing wrong?


Solution

  • I think you can try add %matplotlib inline or ipython notebook --matplotlib inline for a notebook:

    %matplotlib inline
    #ipython notebook --matplotlib inline 
    import pandas as pd
    import matplotlib.pyplot as plt
        
    df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]}) 
    
    df.plot(kind='line')
    

    Or you can add plt.show() for a console:

    import pandas as pd
    import matplotlib.pyplot as plt
        
    df = pd.DataFrame({'Y':[1, 3, 5, 7, 9], 'X':[0, 2, 4, 6, 8]}) 
    
    df.plot(kind='line')
    plt.show()