简体   繁体   English

用大叶绘制热量 map

[英]Plotting a heat map with Folium

I am trying to plot a heat map with folium to show accident prone areas in the city but the map won't display.我正在尝试用 plot 加热 map 以显示城市中的事故多发区域,但 map 不会显示。

First I generated the basemap with the code below which worked perfectly fine:首先,我使用以下代码生成了底图,该代码运行良好:

def generateBaseMap(default_location=[-1.286389,36.817223], default_zoom_start=12):
    base_map = folium.Map(location=default_location, control_scale=True, 
    zoom_start=default_zoom_start)
    return base_map
base_map = generateBaseMap()
base_map

Then I tried applying a heatmap to the basemap and that's where I'm having problems:然后我尝试将热图应用于底图,这就是我遇到问题的地方:

from folium import plugins
import folium.plugins as plugins
from folium.plugins import HeatMap
from folium.plugins import HeatMapWithTime

nrb1=HeatMap(data=df[['latitude','longitude']].groupby(['latitude','longitude']).sum().reset_index().values.tolist(), radius=7, max_zoom=10).add_to(base_map)

nrb1.save("Heatmap.png")
nrb1

All that I'm getting is: <folium.plugins.heat_map.HeatMap at 0x7fd607c04790> .我得到的只是: <folium.plugins.heat_map.HeatMap at 0x7fd607c04790> No error message, no map displayed either.没有错误消息,也没有显示 map。 What am I doing wrong我究竟做错了什么

You're trying to display the HeatMap object, but I think you need to display the Map您正在尝试显示热图 object,但我认为您需要显示 Map

Try the following尝试以下

# Create the HeatMap then add to base_map
HeatMap(data=df[['latitude','longitude']].groupby(['latitude','longitude']).sum().reset_index().values.tolist(), radius=7, max_zoom=10).add_to(base_map)

# display map
base_map

Thank you so much Bob, that worked perfectly well.非常感谢鲍勃,效果很好。

I have one more question, slightly unrelated, I have been using juplyterlab which by default opens with safari and lately when I plot the maps they start to flicker with a message that says "make this notebook trusted to load map: file ->trust notebook" but when I use colab on chrome, it works just fine.我还有一个问题,稍微不相关,我一直在使用 juplyterlab,默认情况下它以 safari 打开,最近当我 plot 时,地图开始闪烁,并显示一条消息,上面写着“使此笔记本受信任以加载 Z1D78B58ED512214911441Trustnotebook: “但是当我在 chrome 上使用 colab 时,它工作得很好。 However, I prefer jupyterlab/jupyter notebook because the files don't get lost due to runtime and I can use it offline, is there sth I can do about this?但是,我更喜欢 jupyterlab/jupyter notebook,因为文件不会因为运行时间而丢失,而且我可以离线使用它,我能做些什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM