HeatMap fails silently on incompatible data type
See original GitHub issueimport 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We should add a validation step in the initialization of
Heatmap
that checks if thedata
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?
Alright I found the problem, it’s with using
zip
. TheHeatmap
class cannot handle that and it stays azip
object in unpacking. Unfortunately it fails silently.You can solve this by converting it into a list before creating
Heatmap
.