Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

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, and create the figure and add it to a subplot. We already went through these steps in the previous Time for action section, 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 section as well.

The stock volume using a logarithmic scale for DISH appears 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 as...