You are on page 1of 2

import matplotlib.

pyplot as plt
import mplleaflet
import pandas as pd

def leaflet_plot_stations(binsize, hashid):

df = pd.read_csv('data/C2A2_data/BinSize_d{}.csv'.format(binsize))

station_locations_by_hash = df[df['hash'] == hashid]

lons = station_locations_by_hash['LONGITUDE'].tolist()
lats = station_locations_by_hash['LATITUDE'].tolist()

plt.figure(figsize=(8,8))

plt.scatter(lons, lats, c='r', alpha=0.7, s=200)

return mplleaflet.display()

leaflet_plot_stations(400,'fb441e62df2d58994928907a91895ec62c2c42e6cd075c2700843b89
')

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data =
pd.read_csv('data/C2A2_data/BinnedCsvs_d400/fb441e62df2d58994928907a91895ec62c2c42e
6cd075c2700843b89.csv')

data2015 = data.where(data['Date'].str.contains('2015')).dropna()
data2015['Date'] = data2015.Date.str[5:]
print(data2015.head())

data['Date'] = data.Date.str[5:]
print(data.head())

data = data.where(data['Date'] != '02-29')

record_high = data.groupby('Date')['Data_Value'].max()
print(record_high.head())

record_low = data.groupby('Date')['Data_Value'].min()
print(record_low.head())

high2015 = data2015.groupby('Date')['Data_Value'].max()
print(high2015.head())

low2015 = data2015.groupby('Date')['Data_Value'].min()
print(low2015.head())

observation_dates = list(range(1,366))

x = np.linspace(1,365,365)
y = np.linspace(1,365,365)

record_high2015 = high2015[high2015 >= record_high.reindex_like(high2015)]


print(record_high2015.head())
x = [n for n in range(0,365) if (high2015.iloc[n] >= record_high.iloc[n]) ]
print(x)

record_low2015 = low2015[low2015 <= record_low.reindex_like(low2015)]


print(record_low2015.head())

y = [n for n in range(0,365) if (low2015.iloc[n] <= record_low.iloc[n]) ]


print(y)

plt.figure(figsize=(12,10))
ax1 = plt.gca()

ax1.set_xlabel('Day of the year')


ax1.set_ylabel('Temperature (tenths of degrees C)')
ax1.set_title('Record highest and lowest temperature by day of the year')

plt.plot(observation_dates,record_high,'-o',observation_dates,record_low,'-
o',zorder=1)
ax1.legend(['record high temperatures', 'record low temperatures'])

plt.scatter(x,record_high2015,s=100,c='red',zorder=2,alpha=0.7)
plt.scatter(y,record_low2015,s=100,c='red',zorder=2,alpha=0.7)

ax1.legend(['record high temperatures', 'record low temperatures','record broken in


2015'])

ax1.fill_between(observation_dates,record_high, record_low, facecolor='blue',


alpha=0.25)

for spine in plt.gca().spines.values():


spine.set_visible(False)

plt.show()

You might also like