question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HeatMap fails silently on incompatible data type

See original GitHub issue
import pandas as gpd
import folium
from folium.plugins import HeatMap

# loading the shapefile and adding it to the folium map
shp = gpd.read_file('./shapefiles/fortal118.shp')
shp.crs = "+proj=utm +zone=24 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +south"
shp = shp.to_crs("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

Map = folium.Map(location=[-3.731862, -38.526669], zoom_start=12, tiles='cartodbpositron')
folium.GeoJson(shp).add_to(Map)

# loading the data to use in order to make the heatmap
cases2011 = pd.read_csv('cases2011.txt', sep=" ", names=['day', 'month', 'lon', 'lat', 'label'], usecols=['lon', 'lat'])
cases2011['amount'] = np.random.randint(0, 100, size=len(cases2011))

# constructing the heatmap and adding it to the folium map
max_amount = float(cases2011['amount'].max())
hm_wide = HeatMap(zip(cases2011.lat.values, cases2011.lon.values, cases2011.amount.values),
                 min_opacity=0.1,
                 max_val=max_amount,
                 radius=17, blur=15,
                 max_zoom=10)
Map.add_child(hm_wide)
# showing the figure
Map

Problem description

The issue is that it was supposed to show a figure with the folium map, the shapefile and the heatmap generated. The heatmap is not displayed, just the folium map and the shapefile appears.

Expected Output

The expected output should be similar to the figure of this post tutorial https://alcidanalytics.com/p/geographic-heatmap-in-python

Output of folium.__version__

0.5.0

Could anyone help me with this issue, please?

Necessary data

shapefiles.zip cases2011.txt

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
Conengmocommented, Aug 10, 2018

We should add a validation step in the initialization of Heatmap that checks if the data argument is a valid type (iterable or array or maybe also pandas types?) and has a valid shape.

Does somebody want to make a PR with this?

1reaction
Conengmocommented, Aug 10, 2018

Alright I found the problem, it’s with using zip. The Heatmap class cannot handle that and it stays a zip object in unpacking. Unfortunately it fails silently.

You can solve this by converting it into a list before creating Heatmap.

data = list(zip(cases2011.lat.values, cases2011.lon.values, cases2011.amount.values))
hm_wide = HeatMap(data)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Type error in visualising pandas dataframe as heatmap
I figured it out after a while: Appears that the type of DF.values was set to object . It can be fixed by...
Read more >
Creating a Heatmap using QGIS - YouTube
In this tutorial, you will learn how to use QGIS in order to develop a heatmap based on a given set of point...
Read more >
Quick Help - FAQ-1015 How to customize Heatmap?
Prepare your custom tick labels and put them in a new column. Open Axis dialog. Activate the Tick Label tab and then Display...
Read more >
Heatmap
The Heatmap is a Bloomreach Google Chrome extension that allows you to see how your customers are shopping on your web page. This...
Read more >
How to Create a Website Heatmap in 5 Minutes [Free Tool]
To get a heatmap of any site page you are interested in, you need to use a heat mapping tool like Hotjar to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found