dailylog 4-30-20
Delay last frame -delay 300
PREP THE DATA
import pandas as pd
import plotly.express as px
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
fips = pd.read_csv('county_fips.csv')
fips_ga = fips[fips['State'] == 'GA']
fips_ga_dict = dict(zip(fips_ga.Name,fips_ga.FIPS))
fips_ga_dict
df = pd.read_csv('all_georgia.csv')
def get_fips(county):
try:
return fips_ga_dict[county]
except:
return 'na'
df['fips'] = df.apply(lambda x: get_fips(x['name']), axis=1)
MAKE THE PLOT
def make_plot(df):
date = df.columns[0]
fig = px.choropleth(df, geojson=counties, locations='fips', color=date,
color_continuous_scale="Viridis",
range_color=(0, 1000),
scope="usa",
labels={'2020-04-25':'infected'}
)
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(
title={
'text': date,
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
coloraxis_colorbar=dict(
title="Number of infections",
titleside="top",
tickmode="array",
tickvals=[0, 100, 500, 1000, 2000],
ticktext=["0", "100", "500", "1000", ">2000"],
ticks="outside"
)
)
filename = 'georgia_v4' + date + '.png'
fig.write_image(filename)
fig.show()
DO THE THING
for col in df.columns[1:-1]:
sm_df = df[[col, 'fips']]
make_plot(sm_df)