Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 772
Amani Avatar asked Feb 24 '16 06:02

Amani


People also ask

How do I plot columns in pandas?

To plot a specific column, use the selection method of the subset data tutorial in combination with the plot() method. Hence, the plot() method works on both Series and DataFrame .

How do I visualize pandas DataFrame?

In order to visualize data from a Pandas DataFrame , you must extract each Series and often concatenate them together into the right format. It would be nicer to have a plotting library that can intelligently use the DataFrame labels in a plot.


2 Answers

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

%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 try:

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()
like image 80
jezrael Avatar answered Nov 02 '22 23:11

jezrael


Start your IPython session with the option --matplotlib:

ipython --matplotlib

This should give you a second window after this line df.plot(kind='line') and pressing <Enter>.:

enter image description here

You can keep the window open. For example:

In [4]: from matplotlib import pyplot as plt
In [5]: plt.title('Test')
Out[5]: <matplotlib.text.Text at 0x1124ed908>

Now you should see the title Test on your plot. If it does not update try draw():

In [6]: plt.draw()
like image 21
Mike Müller Avatar answered Nov 03 '22 00:11

Mike Müller