%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np
!head '../data/paris_weather.dat'
# Searching for GHCND series nr FR000007150 # coordinates: 48.82N, 2.34E, 75.0m; GHCN-D station code: FR000007150 PARIS-14E_PARC_MONTSOURIS France # WMO station 7156 # TMAX GHCN-D V2.0 data with QC in [Celsius] # The non-U.S. data cannot be redistributed within or outside of the U.S. for any commercial activities. 1900 1 1 10.10 1900 1 2 12.00 1900 1 3 9.30 1900 1 4 8.30 1900 1 5 6.00
temperatures = np.loadtxt('../data/paris_weather.dat',
dtype=[('year', 'i8'),
('month', 'i8'),
('day', 'i8'),
('temp', 'f8')])
from goodies import as_table
as_table(temperatures)
year | month | day | temp |
---|---|---|---|
1900 | 1 | 1 | 10.1 |
1900 | 1 | 2 | 12.0 |
1900 | 1 | 3 | 9.3 |
1900 | 1 | 4 | 8.3 |
1900 | 1 | 5 | 6.0 |
1900 | 1 | 6 | 3.3 |
1900 | 1 | 7 | 6.1 |
1900 | 1 | 8 | 8.5 |
1900 | 1 | 9 | 9.3 |
1900 | 1 | 10 | 7.4 |
plt.plot(temperatures['temp'])
[<matplotlib.lines.Line2D at 0x11015be50>]
import datetime
dates = [datetime.date(year,month,day) for year, month, day, T in temperatures]
major = mdates.YearLocator()
minor = mdates.MonthLocator()
plt.plot(dates, temperatures['temp'])
plt.xlabel('year')
plt.ylabel('max day temperature')
plt.xlim(datetime.datetime(2009,1,1), datetime.datetime(2014,1,1))
ax = plt.gca()
ax.xaxis.set_major_locator(major)
ax.xaxis.set_minor_locator(minor)
from statsmodels.nonparametric.smoothers_lowess import lowess
plt.plot(dates, temperatures['temp'])
x = np.array(dates, dtype=np.datetime64)
smoothed_temp = lowess(temperatures['temp'], x,
return_sorted=False,
frac=0.003,
delta=10)
plt.plot(dates, smoothed_temp, color='r', lw=2)
plt.xlabel('year')
plt.ylabel('max day temperature')
plt.xlim(datetime.datetime(2009,1,1), datetime.datetime(2014,1,1))
ax = plt.gca()
ax.xaxis.set_major_locator(major)
ax.xaxis.set_minor_locator(minor)
plt.text(0.58, 0.05, 'Data source: KNMI Climate Explorer',
transform=ax.transAxes, size=8)
<matplotlib.text.Text at 0x10ff05190>