NBK
NBK

Reputation: 905

python folium heatmap not displaying

I'm trying to create a heatmap from geographic point data using folium but can't make the map display. The data called df looks like this:

 lon          lat
-70.979868  -33.679843
-70.969798  -33.673900
-70.969040  -33.696048
-70.947613  -33.678202
-70.940072  -33.674478

I create the base map using Map:

from folium import Map
from folium.plugins import HeatMap    
hmap = Map(location=[-33.45, -70.65], control_scale=True, zoom_start=11, )

And then create a layer on top using HeatMap:

hm_ap = HeatMap(list(zip(df.lat.values, df.lon.values)), 
                radius=8, max_zoom=13).add_to(hm_ap)
hm_ap

The code apparently works, but the output is the following:

<folium.plugins.heat_map.HeatMap at 0x21cd9088588>

You know why the map is not being displayed?

Upvotes: 0

Views: 654

Answers (1)

ilyankou
ilyankou

Reputation: 1329

It looks like you might be adding the heatmap layer to itself (.add_to(hm_ap)), but you need to add it to the map (which is hmap).

First you create your map:

from folium import Map
from folium.plugins import HeatMap

hmap = Map(location=[-33.45, -70.65], control_scale=True, zoom_start=11)

Then you create your HeatMap layer and add it to the map:

heatmap_layer = HeatMap(list(zip(df.lat.values, df.lon.values)), 
                radius=8, max_zoom=13)
heatmap_layer.add_to(hmap)

Then you should be able to view it:

hmap

Upvotes: 1

Related Questions