108

I am trying to plot some data using pandas in Ipython Notebook, and while it gives me the object, it doesn't actually plot the graph itself. So it looks like this:

In [7]:

pledge.Amount.plot()

Out[7]:

<matplotlib.axes.AxesSubplot at 0x9397c6c>

The graph should follow after that, but it simply doesn't appear. I have imported matplotlib, so that's not the problem. Is there any other module I need to import?

chrisfs
  • 6,182
  • 6
  • 29
  • 35
  • I was able to plot things a couple days ago, while following a video,but now I can't seem to plot anything. and I seem to be doing the same thing as the documentation. http://pandas.pydata.org/pandas-docs/stable/visualization.html So I figure something with my system is wrong or a module isn't imported – chrisfs May 09 '12 at 07:00
  • @chrisfs there is a newer correct answer. The one you selected a few years ago is now incorrect. Will you consider changing your accepted answer? Thanks. – tumultous_rooster Jul 02 '15 at 17:48

7 Answers7

184

Note that --pylab is deprecated and has been removed from newer builds of IPython, The recommended way to enable inline plotting in the IPython Notebook is now to run:

%matplotlib inline
import matplotlib.pyplot as plt

See this post from the ipython-dev mailing list for more details.

chrisfs
  • 6,182
  • 6
  • 29
  • 35
Tal Yarkoni
  • 2,534
  • 1
  • 17
  • 12
50

Edit:Pylab has been deprecated please see the current accepted answer

Ok, It seems the answer is to start ipython notebook with --pylab=inline. so ipython notebook --pylab=inline This has it do what I saw earlier and what I wanted it to do. Sorry about the vague original question.

chrisfs
  • 6,182
  • 6
  • 29
  • 35
  • 26
    Yes, that's what you need. You can also run `%pylab inline` inside a notebook to enable pylab mode. – Thomas K May 10 '12 at 11:52
  • 3
    note that it does not have to be in inline mode though for pandas to work. I am happily using just `ipython notebook --pylab` with pandas to have the plot in an extra window, if that's what someone wants. – K.-Michael Aye Dec 18 '12 at 20:22
27

With your import matplotlib.pyplot as plt just add

plt.show()

and it will show all stored plots.

eumiro
  • 207,213
  • 34
  • 299
  • 261
  • 1
    ok that helps. I thought Ipython would do inline plots automatically. The documentation for pandas also doesn't show having to do plt.show() http://pandas.pydata.org/pandas-docs/stable/visualization.html – chrisfs May 09 '12 at 07:03
4

simple after importing the matplotlib you have execute one magic if you have started the ipython as like this

ipython notebook 

%matplotlib inline 

run this command everything will be shown perfectly

Brent Washburne
  • 12,904
  • 4
  • 60
  • 82
Ankanna
  • 737
  • 2
  • 8
  • 21
1

start ipython with ipython notebook --pylab inline ,then graph will show inline.

pigletfly
  • 1,051
  • 1
  • 16
  • 32
-2
import matplotlib as plt
%matplotlib as inline
sshashank124
  • 31,495
  • 9
  • 67
  • 76
-5

All you need to do is to import matplotlib.

import matplotlib.pyplot as plt 
Asclepius
  • 57,944
  • 17
  • 167
  • 143