Skip to content

Instantly share code, notes, and snippets.

@betterdatascience
Created December 11, 2020 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betterdatascience/b62d809ceb4a6b4f18b959865b1358a0 to your computer and use it in GitHub Desktop.
Save betterdatascience/b62d809ceb4a6b4f18b959865b1358a0 to your computer and use it in GitHub Desktop.
006_folium
def generate_color(magnitude):
if magnitude <= 5:
c_outline, c_fill = '#ffda79', '#ffda79'
m_opacity, f_opacity = 0.2, 0.1
else:
c_outline, c_fill = '#c0392b', '#e74c3c'
m_opacity, f_opacity = 1, 1
return c_outline, c_fill, m_opacity, f_opacity
def generate_popup(magnitude, depth):
return f'''<strong>Magnitude:</strong> {magnitude}<br><strong>Depth:</strong> {depth} km'''
quake_map = folium.Map(
location=[-16.495477, 174.9663341],
zoom_start=5,
tiles='Stamen Terrain',
width=1024,
height=600
)
for _, row in df.iterrows():
c_outline, c_fill, m_opacity, f_opacity = generate_color(row['mag'])
folium.CircleMarker(
location=[row['lat'], row['long']],
popup=generate_popup(row['mag'], row['depth']),
color=c_outline,
fill=True,
fillColor=c_fill,
opacity=m_opacity,
fillOpacity=f_opacity,
radius=(row['mag'] ** 2) / 3
).add_to(quake_map)
quake_map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment