obtain PDO data from JISAO PDO page and plot

In [1]:
#plot since
tsince="2000-1"
In [2]:
# python packages
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [3]:
#obtain PDO data from
ds=np.DataSource()
f=ds.open("http://jisao.washington.edu/pdo/PDO.latest")
data=np.empty((0,))
for line in f:
    if line[0:2]=="19" or line[0:2]=="20":
        indata=np.array((line.split())[1:],dtype=np.float32)
        data=np.append(data,indata)
f.close()
In [4]:
# make time series using pandas
date_range=pd.date_range(start="1900-1-1",periods=len(data),freq='M')
pdo=pd.Series(data,index=date_range)
In [5]:
#plot form tsince to the latest
plt.fill_between(pdo[tsince:].index,pdo[tsince:],0.,where=(pdo[tsince:]>0),color="red")
plt.fill_between(pdo[tsince:].index,pdo[tsince:],0.,where=(pdo[tsince:]<0),color="blue")
plt.xlabel("Year")
plt.ylabel("PDO")
plt.savefig("PDOsince"+tsince+".png")
In [ ]: