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.
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()
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With