We can plot a year's worth of stock quotes data with the matplotlib.finance
package. This requires a connection to Yahoo Finance, which is the data source.
Determine the start date by subtracting one year from today:
from matplotlib.dates import DateFormatter from matplotlib.dates import DayLocator from matplotlib.dates import MonthLocator from matplotlib.finance import quotes_historical_yahoo from matplotlib.finance import candlestick import sys from datetime import date import matplotlib.pyplot as plt today = date.today() start = (today.year - 1, today.month, today.day)
We need to create the so-called locators. These objects from the
matplotlib.dates
package locate months and days on thex
axis:alldays = DayLocator() months = MonthLocator()
Create a date formatter to format the dates on the
x
axis. This formatter creates a string containing the short name of a month and the year:month_formatter = DateFormatter("%b %Y")
Download the stock...