Time for action – plotting stock volume
Stock volume varies a lot, so let’s plot it on a logarithmic scale. First we need to download historical data from Yahoo Finance, extract the dates and volume, create locators and a date formatter, create the figure, and add to it a subplot. We already went through these steps in the previous Time for action tutorial, so we will skip them here.
Plot the volume using a logarithmic scale.
plt.semilogy(dates, volume)
Now set the locators and format the x-axis as dates. Instructions for these steps can be found in the previous Time for action tutorial as well. The stock volume using a logarithmic scale for DISH would appear as follows:
What just happened?
We plotted stock volume using a logarithmic scale (see logy.py
):
from matplotlib.finance import quotes_historical_yahoo from matplotlib.dates import DateFormatter from matplotlib.dates import DayLocator from matplotlib.dates import MonthLocator import sys from datetime import date import matplotlib.pyplot...