0

I am currently trying to plot (my first) very simple line chart from a Pandas dataframe.

My (partial) code is:

data = {'Date': dates,
    'Daily Return': daily_return,
    'Cumulative': cumulative}

df = pd.DataFrame(data, columns=['Date', 'Daily Return', 'Cumulative'])

ts = df[['Date', 'Cumulative']]

print ts.head()
print ""
print ts.dtypes
ts.plot()

And my output is:

        Date  Cumulative
0 2014-01-02  100.903375
1 2014-01-03  101.344302
2 2014-01-06  101.080674
3 2014-01-07  101.080674
4 2014-01-08  101.493248

Date          datetime64[ns]
Cumulative           float64
dtype: object
Axes(0.125,0.1;0.775x0.8)

showing that "ts" is a legitimate dataframe as I can print out its "head" call and its datatypes.

But no plot window appears - and I do not understand why.

The documentation (found here: http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html) for plotting a Pandas dataframe suggests the following code:

In [2]: ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))

In [3]: ts = ts.cumsum()

In [4]: ts.plot()

Why will my ts.plot() call not work - why is no plot window appearing?

I have searched many information sources and all of them suggest that extremely simple "dataframe.plot()" syntax but I just can not get it to work.

I receive no error message at all.

UPDATE

I cam across this post: matplotlib plot window won't appear and so...

I have run the following commands:

import matplotlib            
print matplotlib.rcParams['backend']

in my console window and get the following message:

Backend WXAgg is interactive backend. Turning interactive mode on.
WXAgg

Is this information at all relevant?

Community
  • 1
  • 1
s666
  • 528
  • 4
  • 13
  • 33
  • are you using ipython? make sure you use the --pylab option – Liam Foley Mar 11 '15 at 16:42
  • If you do `from matplotlib import pyplot` and then `pyplot.plot([1, 2, 3])`, do you see a plot? If not, the problem is likely with how matplotlib is set up, and has nothing to do with pandas. – BrenBarn Mar 11 '15 at 16:42
  • No, nothing shows when I do that - although I have matplotlib running fine in some other scripts that I have - I can even call a user defined plot function that I have defined in another imported module. I am using Pycharm as my environment - I do have iPython but I am not sure how to activate it in Pycharm – s666 Mar 11 '15 at 16:48
  • Have you tried typing pyplot.show() after doing BrenBarn's test? – seaotternerd Mar 11 '15 at 17:24
  • Ok thanks!! so adding plt.show() after each .plot() call works - I can now plot both my pandas dataframe and other pyplot test plots as recommended above. But each successive plot only shows as each previous one is closed...how may I set it up so that if I have multiple dataframe.plot() calls all plot windows open at the same time rather than having to close one before I see the next? – s666 Mar 11 '15 at 17:59

0 Answers0