【发布时间】:2018-08-19 19:17:17
【问题描述】:
当所有 33 个伦敦行政区都包含在 geojson 文件中时,我无法在 jupyter 中显示 folium 地图
但是
如果 geojson 文件中包含的行政区较少,我可以显示叶图。 (最多 23 个)
如果我将地图保存为 html 文件并单独打开它,它就可以正常工作。
这是有效的代码版本(仅使用前 23 个行政区)。
m = folium.Map(location=[51.5, -0.1], zoom_start=10)
m.choropleth(
geo_data={"type":geo_london["type"],"features":geo_london["features"][:23]}, # 23 of the boroughs
data=df["Underground"],
columns=["LA",'Underground'],
key_on='feature.properties.name',
fill_color='BuPu',
fill_opacity=0.9,
line_opacity=0.2,
legend_name='Underground Useage',
highlight=True
)
这是不工作的版本:
m = folium.Map(location=[51.5, -0.1], zoom_start=10)
m.choropleth(
geo_data= geo_london, # all 33 boroughs
data=df["Underground"],
columns=["LA",'Underground'],
key_on='feature.properties.name',
fill_color='BuPu',
fill_opacity=0.9,
line_opacity=0.2,
legend_name='Underground Useage',
highlight=True
)
其他注意事项:
- 我在 python 中使用 json 解析了 geojson 文件,所以 geo_london 是一个 字典
- 如果我第二次执行 m.save('mymap.html') 并打开地图 版本也可以正常工作。
- 如果我不使用 chorepleth 而是使用 folium.GeoJson(geo_london).add_to(m)
- 大叶0.5.0
- 数据是 pandas 数据系列
【问题讨论】:
-
这很奇怪。我想知道您是否收到警告,例如
IOPub data rate exceeded,并且它被某种方式抑制了 -
我发现是谷歌浏览器的问题!在 safari 上似乎不是问题。你可以在这里看到我的笔记本——我在 chrome 上看不到地图,但在 safari 上可以。 nbviewer.jupyter.org/github/mrcork/OCR_LDS/blob/master/…
-
哦,好的。所以你在 Chrome 中运行 Jupyter 并在 Safari 中打开了 html 文件?
-
在 chrome 中打开的 html 文件(在我使用 m.save() 保存地图之后)。但是在 jupyter 中工作不会显示地图。当我在 chrome 中使用 nbviewer 时,我也看不到地图 - 但它在 safari 上加载正常。
标签: pandas jupyter geojson choropleth folium