Python 大叶地图不显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36969991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:37:50  来源:igfitidea点击:

Folium map not displaying

pythoncanopyfolium

提问by mapping dom

Running on canopy version 1.5.5.3123 With;

在 Canopy 版本 1.5.5.3123 上运行;

Folium Version: 0.1.2, Build: 1

Folium 版本:0.1.2,构建:1

The following code;

以下代码;

import folium  
import pandas as pd
LDN_COORDINATES = (51.5074, 0.1278)  
from IPython.display import HTML
import shapefile
#create empty map zoomed in on London
LDN_COORDINATES = (51.5074, 0.1278) 
map = folium.Map(location=LDN_COORDINATES, zoom_start=12)
display(map)  

Returns

退货

<folium.folium.Map at 0x10c01ae10>

But nothing else.

但没有别的。

How do i get to display a map within an ipython notebook?

如何在 ipython 笔记本中显示地图?

采纳答案by emunsing

I've found this tutorial on Folium in iPython Notebooksquite helpful. The raw Folium instance that you've created isn't enough to get iPython to display the map- you need to do a bit more work to get some HTML that iPython can render.

我发现iPython Notebooks 中关于 Folium 的这个教程非常有帮助。您创建的原始 Folium 实例不足以让 iPython 显示地图——您需要做更多的工作来获得一些 iPython 可以呈现的 HTML。

To display in the iPython notebook, you need to generate the html with the myMap._build_map() method, and then wrap it in an iFrame with styling for iPython.

要在 iPython 笔记本中显示,您需要使用 myMap._build_map() 方法生成 html,然后将其包装在带有 iPython 样式的 iFrame 中。

import folium  
from IPython.display import HTML, display
LDN_COORDINATES = (51.5074, 0.1278) 
myMap = folium.Map(location=LDN_COORDINATES, zoom_start=12)
myMap._build_map()
mapWidth, mapHeight = (400,500) # width and height of the displayed iFrame, in pixels
srcdoc = myMap.HTML.replace('"', '&quot;')
embed = HTML('<iframe srcdoc="{}" '
             'style="width: {}px; height: {}px; display:block; width: 50%; margin: 0 auto; '
             'border: none"></iframe>'.format(srcdoc, width, height))
embed

Where by returning embedas the output of the iPython cell, iPython will automatically call display.display()on the returned iFrame. In this context, you should only need to call display()if you're rendering something else afterwards or using this in a loop or a function.

通过embed作为 iPython 单元的输出返回,iPython 将自动调用display.display()返回的 iFrame。在这种情况下,您只需要在display()之后渲染其他内容或在循环或函数中使用它时才需要调用。

Also, note that using mapas a variable name may might be confused with the .map() method of several classes.

另请注意,map用作变量名可能会与几个类的 .map() 方法混淆。

回答by Shehan Ishanka

_build_map() doesn't exist anymore. The following code worked for me

_build_map() 不再存在。以下代码对我有用

import folium
from IPython.display import display
LDN_COORDINATES = (51.5074, 0.1278)
myMap = folium.Map(location=LDN_COORDINATES, zoom_start=12)
display(myMap)

回答by novonimo

Considering the above answers, another simple way is to use it with Jupiter Notebook.

考虑到上述答案,另一种简单的方法是将它与Jupiter Notebook一起使用。

for example (on the Jupiter notebook):

例如(在木星笔记本上):

import folium

london_location = [51.507351, -0.127758]

m = folium.Map(location=london_location, zoom_start=15)
m

and see the result when calling the 'm'.

并在调用“m”时查看结果。

回答by Nevermore

Is there a reason you are using an outdated version of Folium?

您是否有理由使用过时的 Folium 版本?

This ipython notebook clarifies some of the differences between 1.2 and 2, and it explains how to put folium maps in iframes. http://nbviewer.jupyter.org/github/bibmartin/folium/blob/issue288/examples/Popups.ipynb

这个 ipython notebook 澄清了 1.2 和 2 之间的一些差异,并解释了如何将大叶地图放在 iframe 中。 http://nbviewer.jupyter.org/github/bibmartin/folium/blob/issue288/examples/Popups.ipynb

And the code would look something like this (found in the notebook above, it adds a marker, but one could just take it out):

代码看起来像这样(在上面的笔记本中找到,它添加了一个标记,但可以将其取出):

m = folium.Map([43,-100], zoom_start=4)

html="""
    <h1> This is a big popup</h1><br>
    With a few lines of code...
    <p>
    <code>
        from numpy import *<br>
        exp(-2*pi)
    </code>
    </p>
    """
iframe = folium.element.IFrame(html=html, width=500, height=300)
popup = folium.Popup(iframe, max_width=2650)

folium.Marker([30,-100], popup=popup).add_to(m)

m

The docs are up and running, too, http://folium.readthedocs.io/en/latest/

文档也在运行,http://folium.readthedocs.io/en/latest/