Python:没有出现Folium地图

问题描述 投票:0回答:2

我正在尝试使用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

python geojson heatmap matplotlib-basemap folium
2个回答
1
投票

您的代码在Jupyter笔记本中适用于我:

enter image description here

对于脚本,您需要调用save方法,如下所示:

can_map.save('index.html')

0
投票

在Firefox中重新运行代码,它应该在Jupyter笔记本中呈现。当您将地图保存在另一个浏览器中时,保存的文件应该正确打开,即使它最初显示为白色单元格。

© www.soinside.com 2019 - 2024. All rights reserved.