import folium
import pandas as pd
# the geojson data file
SA_geo = '../data/SA_regions.json'
# initialize the map at (23, 45) which is Saudi Arabia
SA_map = folium.Map(location=[23,45], zoom_start=5)
# read the data we want to visualize (obtained from data.gov.sa)
data = pd.read_csv('./goats.csv')
data.head()
Region | 2003 | 2002 | 2001 | |
---|---|---|---|---|
0 | Riyadh | 366769.0 | 422882.0 | 392459.0 |
1 | Makkah | 285647.0 | 246865.0 | 253335.0 |
2 | Madinah | 267826.0 | 239032.0 | 205698.0 |
3 | Qassim | 165556.0 | 169599.0 | 118732.0 |
4 | Eastern Region | 83441.0 | 84432.0 | 53778.0 |
bins = list(data['2001'].quantile([0, 0.25, 0.5, 0.75, 1]))
choropleth = folium.Choropleth(
geo_data=SA_geo,
name='choropleth',
data=data,
columns=['Region', '2001'],
key_on='feature.properties.name',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.3,
legend_name='Estimated Number of Goats in 2001',
bins=bins,
reset=True
).add_to(SA_map)
style_function = "font-size: 15px; font-weight: bold"
choropleth.geojson.add_child(
folium.features.GeoJsonTooltip(['name'], style=style_function, labels=False))
# create a layer control
folium.LayerControl().add_to(SA_map)
SA_map
SA_map.save('SA_regions_map.html')