We can plot a year's worth of stock quotes data with the matplotlib.finance
package. This will require a connection to Yahoo Finance, which will be the data source.
Determine start date: Determine the start date by subtracting 1 year from today.
today = date.today() start = (today.year - 1, today.month, today.day)
Create locators: We need to create so-called locators. These objects from the
matplotlib.dates
package are needed to locate months and days on the x-axis.alldays = DayLocator() months = MonthLocator()
Create a formatter: Create a date formatter to format the dates on the x-axis. This formatter will create a string containing the short name of a month and the year.
month_formatter = DateFormatter("%b %Y")
Download the quotes: Download the stock quote data from Yahoo finance with the code below:
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
Create a figure: Create a Matplotlib
figure
object—this is a top level container...