Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 23, 2020 06:48
Show Gist options
  • Save amankharwal/8d3f8c8d0402fa970a2a94929231ab15 to your computer and use it in GitHub Desktop.
Save amankharwal/8d3f8c8d0402fa970a2a94929231ab15 to your computer and use it in GitHub Desktop.
dict_center_zoom={
'India':[(20.5937,78.9629),2.5],
'Bengaluru':[(12.9716,77.5946),9],
'Delhi':[(28.7041,77.1025),8],
'Mumbai':[(19.0760,72.8777),8],
'Hyderabad':[(17.3850,78.4867),8],
'Chennai':[(13.0827,80.2707),9]
}
def draw_aqi_map(df,city):
if city=='India':
df0 = df
else:
if city=='Bengaluru':
state='Karnataka'
elif city=='Mumbai':
state='Maharashtra'
elif city=='Hyderabad':
state='Telangana'
elif city=='Chennai':
state='Tamil Nadu'
else:
state=city
df0 = df[df['State']==state]
fig = go.Figure()
df1=df0[df0['Period']=='Before']
fig.add_trace(go.Scattermapbox(name='Before Lockdown',
lat=df1.Latitude,
lon=df1.Longitude,
mode='markers',
marker=go.scattermapbox.Marker(
size=17,
color=df1.AQI,
colorscale=scale(df1.AQI),
opacity=0.7
),
text=df1.StationId.astype(str)+'<br><b>Station</b>: '+df1.StationName+'<br><b>AQI</b>: '+np.round(df1.AQI).astype(str),
hoverinfo='text',
subplot='mapbox'
))
df2=df0[df0['Period']=='After']
fig.add_trace(go.Scattermapbox(name='After Lockdown',
lat=df2.Latitude,
lon=df2.Longitude,
mode='markers',
marker=go.scattermapbox.Marker(
size=17,
color=df2.AQI,
colorscale=scale(df2.AQI),
opacity=0.7
),
text=df2.StationId.astype(str)+'<br><b>Station</b>: '+df2.StationName+'<br><b>AQI</b>: '+np.round(df2.AQI).astype(str),
hoverinfo='text',
subplot='mapbox2'
))
fig.update_layout(
height=300,width=600,
title=city + ': Before & After Lockdown',
paper_bgcolor=BGCOLOR,
margin=dict(l=20,r=20,t=40,b=20),
showlegend=False,
autosize=True,
hovermode='closest',
mapbox=dict(accesstoken=secret_value_1,
style='carto-positron',
domain={'x': [0, 0.48], 'y': [0, 1]},
bearing=0,
center=dict(
lat=dict_center_zoom[city][0][0],
lon=dict_center_zoom[city][0][1]
),
pitch=0,
zoom=dict_center_zoom[city][1]
),
mapbox2=dict(accesstoken=secret_value_1,
style='carto-positron',
domain={'x': [0.52, 1.0], 'y': [0, 1]},
bearing=0,
center=dict(
lat=dict_center_zoom[city][0][0],
lon=dict_center_zoom[city][0][1]
),
pitch=0,
zoom=dict_center_zoom[city][1],
),
)
return fig
draw_aqi_map(df_ind,'India')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment