1

I have this pandas data frame set up:

    FY   NY_State
0   1986-87   89431973
1   1987-88   95958200
2   1988-89  100664606
3   1989-90   99703990
4   1990-91   95446076
5   1991-92   91487047
6   1992-93   92658482
7   1993-94   88026334
8   1994-95   90845207
9   1995-96   80070860
10  1996-97   77357591
11  1997-98   87040859
12  1998-99   89547598
13  1999-00   93484650
14  2000-01  118696779
15  2001-02  132748185
16  2002-03  111932612
17  2003-04  116911977
18  2004-05  119898693
19  2005-06  149293542
20  2006-07  161647387
21  2007-08  193891526
22  2008-09  170071041
23  2009-10  180069745
24  2010-11  174704520

FWIW:

In [50]: totalData.dtypes
Out[50]: 
FY          object
NY_State     int64
dtype: object

I want to make a bar chart with the FY on the x-axis and the y-axis being the amount in the NY_State column.

I've been getting some progress with this:

totalData.plot(x=totalData.FY, kind='bar')

but that gives me this: first chart

Then I tried this:

totalData.plot(x=totalData.FY, kind='bar', ylim=(70000000, 240000000))

And that gave me this:

second chart

Which is better, but still not what I want. I tried:

totalData.plot(x=totalData.FY, y=totalData.NY_State, kind='bar')

but that gives me an exception of

IndexError: indices are out-of-bounds

...which makes no sense whatsoever to me how that's possible.

Would really appreciate help.

Community
  • 1
  • 1
  • 1
    It's getting displayed in scientific notation. set `ax=` your plot and then call `ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%d'))` so this is a duplicate of [this](http://stackoverflow.com/questions/3274200/how-do-i-force-matplotlib-to-write-out-the-full-form-of-the-x-axis-label-avoidi) – TomAugspurger Nov 11 '13 at 03:19
  • Just in case I wasn't clear, the scientific notation is the `1e8` at the top left of the plot. It's easy to miss. – TomAugspurger Nov 11 '13 at 03:26
  • @TomAugspurger Thank you. I tried that but now I'm not sure how to visualize the graph again. I tried ax.draw, ax.show(), plt.show() and fig=plt.figure(), fig.add_axes(ax), fig.add_subplot(ax), and then doing fig.draw...none of those work. What can I do? EDIT: I noticed the scientific notation but stupidly didn't make the connection. –  Nov 11 '13 at 03:26
  • `plt.draw()` should do it. Are you using IPython? The code should be `ax = totalData.plot(x=totalData.FY, y=totalData.NY_State, kind='bar'); ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%d')); plt.draw()` – TomAugspurger Nov 11 '13 at 03:28
  • Yep, IPython. This line: `ax = totalData.plot(x=totalData.FY, y=totalData.NY_State, kind='bar')` is giving the indices exception that I mentioned, says that indices are out-of-bounds. –  Nov 11 '13 at 03:30
  • Oh sorry I copy pasted that wrong. Don't include the `y=` argument. You had it right the first time: `totalData.plot(x=totalData.FY, kind='bar')` – TomAugspurger Nov 11 '13 at 03:32
  • @TomAugspurger Ah! Nice, now that works! I notice that if you close the visualized graph and then call plt.draw(), that you get a blank graph, as if you first started....is this because the 'state-machine' of plt is effectively reset after closing the graph? –  Nov 11 '13 at 03:34
  • That sounds about right. You still have access to the axes object in `ax` though. I'm not sure about how to redraw it though. – TomAugspurger Nov 11 '13 at 03:40

0 Answers0