Python : Folium 地图未出现
Python : Folium map not appearing
我正在尝试使用 Folium 为加拿大绘制一些数据。但是,最后,我得到了空白作为没有错误消息的输出。我的代码如下。
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
可以找到我正在使用的json文件here
你的代码在 Jupyter notebook 中对我有用:
对于脚本,你需要调用save
方法,像这样:
can_map.save('index.html')
重新运行 Firefox 中的代码,它应该在 Jupyter notebook 中呈现。
当您在另一个浏览器中保存地图时,保存的文件应该可以正确打开,即使它最初显示为白色单元格。
我正在尝试使用 Folium 为加拿大绘制一些数据。但是,最后,我得到了空白作为没有错误消息的输出。我的代码如下。
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
可以找到我正在使用的json文件here
你的代码在 Jupyter notebook 中对我有用:
对于脚本,你需要调用save
方法,像这样:
can_map.save('index.html')
重新运行 Firefox 中的代码,它应该在 Jupyter notebook 中呈现。 当您在另一个浏览器中保存地图时,保存的文件应该可以正确打开,即使它最初显示为白色单元格。