Book Image

NumPy 1.5 Beginner's Guide

By : Ivan Idris
Book Image

NumPy 1.5 Beginner's Guide

By: Ivan Idris

Overview of this book

<p>In today's world of science and technology, the hype is all about speed and flexibility. When it comes to scientific computing, NumPy is on the top of the list. NumPy is the fundamental package needed for scientific computing with Python. NumPy will give you both speed and high productivity. Save thousands of dollars on expensive software, while keeping all the flexibility and power of your favourite programming language.<br /><br /><i>NumPy 1.5 Beginner's Guide</i> will teach you about NumPy from scratch. It includes everything from installation, functions, matrices, and modules to testing, all explained with appropriate examples. <br /><br /><i>Numpy 1.5 Beginner's Guide</i> will teach you about installing and using NumPy and related concepts.</p> <p>This book will give you a solid foundation in NumPy arrays and universal functions. At the end of the book, we will explore related scientific computing projects such as Matplotlib for plotting and the SciPy project through examples.</p> <p><i>NumPy 1.5 Beginner's Guide</i> will help you be productive with NumPy and write clean and fast code.</p>
Table of Contents (18 chapters)
NumPy 1.5
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – plotting a year's worth of stock quotes


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.

  1. Determine start date: Determine the start date by subtracting 1 year from today.

    today = date.today()
    start = (today.year - 1, today.month, today.day)
  2. 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()
  3. 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")
  4. Download the quotes: Download the stock quote data from Yahoo finance with the code below:

    quotes = quotes_historical_yahoo(sys.argv[1], start, today)
  5. Create a figure: Create a Matplotlib figure object—this is a top level container...