Python : Folium map not appearing
Question:
I am trying to map some data for Canada using Folium. However, in the end, I am getting whitespace as an output with no error message. My code is below.
import folium
import json # or import geojson
with open("geo.json") as json_file:
json_data = json.load(json_file) # geojson file
# create a plain world map
can_map = folium.Map(location=[56.1, 106], zoom_start=2, tiles='Mapbox
Bright')
c2 = {
'Alberta': 144284.48,
'British Columbia': 141222.06000000017,
'Manitoba': 134337.96999999994,
'New Brunswick': 115727.67000000001,
'Newfoundland': 6885.140000000001,
'Northwest Territories': 91755.44000000002,
'Nova Scotia': 80136.18000000005,
'Nunavut': 1506.4300000000014,
'Ontario': 352263.50999999983,
'Prince Edward Island': 28742.2,
'Quebec': 138658.87999999998,
'Saskachewan': 177314.26000000013,
'Yukon': 74404.80000000003
}
# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
can_map.choropleth(
geo_data=json_data,
data=c2,
columns=['Province', 'Profit'],
key_on='feature.properties.name',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Canada data'
)
# display map
can_map
The json file I am using can be found here
Answers:
Re-run the code in Firefox and it should render in Jupyter notebook.
When you save the map in another browser that saved file should open properly even if it appears as a white cell initially.
I am trying to map some data for Canada using Folium. However, in the end, I am getting whitespace as an output with no error message. My code is below.
import folium
import json # or import geojson
with open("geo.json") as json_file:
json_data = json.load(json_file) # geojson file
# create a plain world map
can_map = folium.Map(location=[56.1, 106], zoom_start=2, tiles='Mapbox
Bright')
c2 = {
'Alberta': 144284.48,
'British Columbia': 141222.06000000017,
'Manitoba': 134337.96999999994,
'New Brunswick': 115727.67000000001,
'Newfoundland': 6885.140000000001,
'Northwest Territories': 91755.44000000002,
'Nova Scotia': 80136.18000000005,
'Nunavut': 1506.4300000000014,
'Ontario': 352263.50999999983,
'Prince Edward Island': 28742.2,
'Quebec': 138658.87999999998,
'Saskachewan': 177314.26000000013,
'Yukon': 74404.80000000003
}
# generate choropleth map using the total immigration of each country to Canada from 1980 to 2013
can_map.choropleth(
geo_data=json_data,
data=c2,
columns=['Province', 'Profit'],
key_on='feature.properties.name',
fill_color='YlOrRd',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Canada data'
)
# display map
can_map
The json file I am using can be found here
Re-run the code in Firefox and it should render in Jupyter notebook.
When you save the map in another browser that saved file should open properly even if it appears as a white cell initially.