5

I've installed Enthought's EPD (64 bit for Windows 7).

I'm trying to plot historical stock quote data using Yahoo's API. All the code I'm trying to use is on this blog post: http://www.traineetrader.com/importing-stock-data-from-yahoo-using-python/

The ystockquote.py file works fine.

But the second script to plot Google's historical stock quote doesn't work for me. This is the code (from the website):

import ystockquote

# Get Quotes 01/01/2006 - 01/01/2009
GOOG = ystockquote.get_historical_prices('GOOG', '20060101', '20090101')

# Create empty lists, quick and dirty
GOOGOpen = [ ]
GOOGClose = [ ]
GOOGDate = [ ]
GOOGHigh = [ ]
GOOGLow = [ ]
GOOGAdj = [ ]
GOOGVolume = [ ]

# Populate lists from downloaded data
for i in range(1, 755):
    GOOGDate.append(GOOG[i][0])
    GOOGOpen.append(GOOG[i][1])
    GOOGHigh.append(GOOG[i][2])
    GOOGLow.append(GOOG[i][3])
    GOOGClose.append(GOOG[i][4])
    GOOGVolume.append(GOOG[i][5])
    GOOGAdj.append(GOOG[i][6])

plot(GOOGAdj)
title("Google Adjusted Close")
ylabel(r"GOOG Closing Price ($USD)", fontsize = 12)
xlabel(r"Date", fontsize = 12)
grid(True)

I get the following error:

NameError: name 'plot' is not defined

Any tips on what I'm doing wrong? Or how to get this to run? If I include "from pylab import *" at the top of the code, I don't get the error, but nothing happens.

2
  • I should note that I'm running this script from the PyLab interpreter. Commented Oct 17, 2011 at 3:53
  • 2
    N.B. If you start ipython --pylab, it loads the pylab stuff automatically, and also uses some tricks so the console doesn't block when plot windows are open. Commented Oct 18, 2011 at 12:16

1 Answer 1

7

In addition to adding from pylab import *, you need to add show() after the last line of the script (i.e., after grid(True)) in your question to actually display the plot.

Here is what I get after adding show():

Google Adjusted Close

Sign up to request clarification or add additional context in comments.

1 Comment

The figure, of course, matches the figure in the blog post linked to in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.