Last active
July 29, 2019 18:35
-
-
Save AlexKaravaev/70ab5e67b54e2cebf3b99a68830e4d32 to your computer and use it in GitHub Desktop.
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
custom_style = "mapbox://styles/alex492/cjyil3dry03rl1cqr4mlut05k" | |
data = [] | |
# Create data for each substance | |
for subst_name in df.columns[1:-2].tolist(): | |
subst_data = go.Scattermapbox( | |
lat= df['lat'], | |
lon= df['lon'], | |
mode='markers+text', | |
visible=False, | |
marker=dict( | |
size= 100, | |
color = df[subst_name], | |
opacity = 0.5, | |
showscale=True, | |
symbol="circle", | |
colorbar=dict( | |
title=dict( | |
text=subst_name) | |
) | |
), | |
hoverinfo='text+name', | |
text=df['Адрес'], | |
textfont=dict( | |
size=10, | |
color="white") | |
) | |
data.append(subst_data) | |
# Map layout | |
layout = go.Layout(autosize=False, | |
mapbox= dict(accesstoken=access_token, | |
bearing=10, | |
pitch=0, | |
zoom=10, | |
center= dict(lat=59.939, | |
lon=30.344), | |
style=custom_style), | |
width=900, | |
height=600, | |
title = "air_pollution_record") | |
# Text annotation in the bottom | |
annotation = [ | |
dict( | |
text='Air pollution in Saint-Petersburg record based on few days mean', | |
font = dict(size=15,color='white'), | |
x = 0.05, y=0.05, xref='paper', yref='paper', align='center', | |
showarrow=False, bgcolor='black' | |
) | |
] | |
# Buttons, that allow you to choose, which substance to show | |
updatemenu = [ | |
dict( | |
buttons = [dict( | |
label=subst_name, | |
method='update', | |
execute=True, | |
# Create boolean mask, based on what data to render | |
# Ex. [True, False, False, False, False, False, False] - To render first substance | |
# [False, True, False, False, False, False, False] - To render second substance | |
args=[dict(visible=[i==j for i in range(len(df.columns[1:-2].tolist()))])]) | |
for j,subst_name in enumerate(df.columns[1:-2].tolist()) | |
], | |
type='buttons', | |
bgcolor = 'black', | |
showactive = False, | |
font = dict(size=15, color='white'), | |
active = 0 | |
) | |
] | |
layout['annotations'] = annotation | |
layout['updatemenus'] = updatemenu | |
fig = dict(data=data, layout=layout) | |
plotly.offline.iplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment