Created
February 20, 2022 21:10
-
-
Save alanjones2/e85072ad7305bdb01bfafc40bd9ed82d to your computer and use it in GitHub Desktop.
voila weather
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import ipywidgets as widgets | |
weather=pd.read_csv('heathrowDataFiltered.csv') | |
def fmax(year): | |
yticks = [0,5,10,15,20,25,30] | |
label="Degrees Celsius" | |
f(year, 'Tmax','line', yticks, label) | |
def fmin(year): | |
yticks = [0,5,10,15,20,25,30] | |
label="Degrees Celsius" | |
f(year, 'Tmin','line',yticks, label) | |
def frain(year): | |
yticks = [0,10,20,30,40,50,60,70,80,90,100] | |
label="Millimetres" | |
f(year, 'Rain','bar',yticks, label) | |
def fsun(year): | |
yticks = [0,50,100,150,200,250,300] | |
label="Hours" | |
f(year, 'Sun','bar', yticks, label) | |
def f(year,y, kind, yticks,label): | |
xticks= [1,2,3,4,5,6,7,8,9,10,11,12] | |
xlabels = ['Jan','Feb','Mar','Apr','May', | |
'Jun','Jul','Aug','Sep','Oct','Nov','Dec'] | |
ax = weather[weather['Year']==year].plot(kind = kind, y = y, | |
x ='Month', yticks = yticks, | |
xticks = xticks, legend = False, | |
title = y) | |
ax.set_xticklabels(xlabels) | |
ax.set_ylabel(label) | |
year = widgets.IntSlider(description='Select year', | |
min = weather.Year.min(), | |
max = weather.Year.max(), | |
value = (weather.Year.max()+weather.Year.min())/2, | |
layout=widgets.Layout(width='500px')) | |
chartmax = widgets.interactive_output(fmax, {'year':year}) | |
chartmin = widgets.interactive_output(fmin, {'year':year}) | |
chartrain = widgets.interactive_output(frain, {'year':year}) | |
chartsun = widgets.interactive_output(fsun, {'year':year}) | |
header = widgets.HTML(value="<h1>Monthly weather data</h1>Adjust the slider below the chart to select year") | |
grid = widgets.GridspecLayout(4, 2, height='900px', width='1000px') | |
grid[0,:2]=header | |
grid[1,0]=chartmin | |
grid[1,1]=chartmax | |
grid[2,0]=chartrain | |
grid[2,1]=chartsun | |
grid[3,0:2]=year | |
grid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment