chrisfs
chrisfs

Reputation: 6333

How do I display multiple charts in pandas python

Using Ipython notebook and the pandas module, I have a bit of code that iterates through a series and makes a number of bar charts (or is supposed to). It only produces the last chart that it should. The data is the funds raised by day and radio show, and I want a chart for each day. I suspect this may be a combo pandas/ipython problem, but I don't know how to approach it.

The code is this:

print pledge[pledge.Date==k[0]].groupby('Break')['Amount'].sum().plot(kind='bar')
kcount =0;••••••••••••••••••••
for k, v in grouped.Amount.iteritems():
    if k[0] <> kcount:
        kcount=k[0]
        print k[0];
        print pledge[pledge.Date==k[0]].groupby('Break')['Amount'].sum().plot(kind='bar')

and the output I get is

05/02/2012 

Axes(0.125,0.125;0.775x0.775)

05/03/2012

Axes(0.125,0.125;0.775x0.775) 

05/04/2012 

Axes(0.125,0.125;0.775x0.775)

05/05/2012 

Axes(0.125,0.125;0.775x0.775) 

05/06/2012

Axes(0.125,0.125;0.775x0.775)

Bar chart

With only a single chart at the end, of the last iteration.

Upvotes: 2

Views: 4631

Answers (2)

Wes McKinney
Wes McKinney

Reputation: 105661

Each of those plots appears on the same subplot; pandas creates a figure in the first plot call but leaves it to you to create further figures and subplots after that. Try inserting plt.figure() (cf. import matplotlib.pyplot as plt) before each plot command.

Upvotes: 5

Thomas K
Thomas K

Reputation: 40390

You can't print a plot object (or you can, but you only see the Axes(...) text).

IPython should make a display() function available that you can use on each plot to show it.

Upvotes: 0

Related Questions