# Class 16: matplotlib 2 - graphing

## Table of Contents

## Introduction

This is part 2 of the matplotlib introduction. The material in classes 15 and 16 is covered in a video:

## Last time - lecture 15

We had this script last time to create the x,y offsets in meters of the GPS

#!/usr/bin/env python import pyproj import numpy as np def wander_list(): geod = pyproj.Geod(ellps='WGS84') x,y,z,quality,satellites,hdop = np.loadtxt('2011-10-11.gga.dat.bz2', unpack=True) x_ave = np.average(x) y_ave = np.average(y) print x_ave,y_ave print '__name__:', __name__ if __name__ == '__main__': wander_list()

We want to create a better script that can save the data out for reuse.

## Matplotlib continued

import wander reload wander # You have to reload after the first import to get more changes dir, m = wander.wander_list('2011-10-11.gga.dat.bz2') cla() plot dir

Errr… dir runs -180 to +180. Let's make that 0..360:

dir360 = [ d if d>0 else d+360 for d in dir ]

Didn't get that last line? I'll explain it more in a video.

## Fancier plotting - histograms and subplots

It would be nice to be able to make a figure with multiple plots and maybe have a histogram. Let's try making a histogram first.

cla() hist(m) hist(m, bins=30) hist(m, bins=100)

Which is a reminder that you are warned that histograms are not a stable concept. How they look depends heavily on the number of bins.

**Warning:** matplotlib is designed to follow how matlab does plotting. That
means that subplots start counting from 1, not 0. Bummer.

cla() subplot (411) plot(dir360) plot(x) subplot (412) plot(y) subplot (413) plot(m) subplot (414) hist(m, bins=200)

## Working with arrays

We can start building up capabilities

zeros(30) ones(10) concatonate( (zeros(100), ones(100), zeros(100) ) )

## TODO Questions

- What is "interactive mode" for matplotlib?
- Switching figures
- Splitting 15 into 15 & 16

Date: <2011-10-25 Tue>

HTML generated by org-mode 7.4 in emacs 23