#!/usr/local/bin/python3 # -*- coding: utf-8 -*- #======================================================================= # name: plot_timeseries.py # # category: python script # # description: # This is a sample program to plot time series. # # author: M. Yoshimori (masakazu AT aori.u-tokyo.ac.jp) #======================================================================= import os import numpy as np import pandas as pd import matplotlib.pylab as plt # specify input & output files fin0 = "../analysis/out/HadCRUT5.0Analysis_gl_ann.dat" fin1 = "../analysis/out/HadCRUT5.0Analysis_nh_ann.dat" fin2 = "../analysis/out/HadCRUT5.0Analysis_sh_ann.dat" fout = "hadcrut5" #---------------- # read ASCII data #---------------- # open ASCII files to read d = pd.read_csv(fin0, header=None, delim_whitespace=True) # read data without header t = d.values.T[0,:] # pandas to ndarray for the 1st column gl = d.values.T[1,:] # pandas to ndarray for the 2nd column d = pd.read_csv(fin1, header=None, delim_whitespace=True) # read data without header #t = d.values.T[0,:] # pandas to ndarray for the 1st column nh = d.values.T[1,:] # pandas to ndarray for the 2nd column d = pd.read_csv(fin2, header=None, delim_whitespace=True) # read data without header #t = d.values.T[0,:] # pandas to ndarray for the 1st column sh = d.values.T[1,:] # pandas to ndarray for the 2nd column #----- # plot #----- fig = plt.figure() ax = fig.add_subplot(111) plt.plot(t,gl,'k-',label='Global') plt.plot(t,nh,'r-',label='N. Hem.') plt.plot(t,sh,'b-',label='S. Hem.') plt.xlim(1850,2020) plt.ylim(-0.8,1.4) plt.title('HadCRUT5') plt.xlabel('Year') plt.ylabel('Surface air temperature anomaly [$^\circ$C]') ax.legend() plt.grid() plt.show() fig.savefig('hadcrut5.png')