You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi - I love what you have created here - today I manage to get an aggregate query from elastic search displayed on a Folium map in a few hours - it was really easy!
Now I am trying to add popups, but I cannot see any example that shows how to get a popup on a choropleth map - could someone point me in the right direction please.
I would just want to display the value associated with the polygon. I was thinking of adding the value back to the underlying geojson object and then adding that on as some form of transparent layer on top of the choropleth - but not having much luck!!
If you point me in the right direction I will create an example notebook for others as thanks ;-) My coding probably is not up to much more contribution at this stage!
I think the GeoJsonTooltip class adds the functionality requested in this issue. It's available since 0.6.0. It doesn't work with the Map.choropleth method easily though, users have to manually get the GeoJson or TopoJson object created by Map.choropleth and add their GeoJsonTooltip to that.
I think the GeoJsonTooltip class adds the functionality requested in this issue. It's available since 0.6.0. It doesn't work with the Map.choropleth method easily though, users have to manually get the GeoJson or TopoJson object created by Map.choropleth and add their GeoJsonTooltip to that.
could you elaborate on it with an example illustrating how to add a tooltip to a choropleth?
I'm trying to do that exact thing and failing.
Check the docstring for GeoJsonTooltip to reference its functionality with the help command, it covers the functionality pretty well.
I have a a notebook example in my geojsonmarkers PR (not yet merged) that demonstrates it how the GeoJsonTooltip can be used. The marker argument is not yet active (I need to fix a few things) but the tooltipping will work the same way for a Choropleth/Polygon map.
Thanks, @jtbaker .
I'm starting to understand, but am not all the way there yet.
Yes, i am on the 0.6.0 release.
I can create a choropleth with my tiles, GeoJSON layer, and colorscale.
I can create a tooltip on a copy of the original GeoJSON layer like you do in your notebook.
But how do i replace the choropleth GeoJSON layer with the second one that has the tooltip and still keep the choropleth colorscale?
Or am i going about this wrong?
This conditional styling is done using the style_function argument in GeoJson. It takes a function as an an argument, which will evaluate on each feature in the dataset, and return a value based on the logic you give it. For simple fill colors, its easiest to pass a lambda function and query the object properties directly.
I think it is just more straightforward to query directly against the value instead of creating a new series/dict, just remember you have to pass through the properties key to get to your actual key value.
branca, a sibling of folium that you should have as well makes it easier to cook up linear and step colorscales with the use of d3.
@Conengmo Actually adding a geojsonpopup to a geojson based choropleth map doesn't work. It gives TypeError: You cannot add a GeoJsonPopup to anything other than a GeoJson or TopoJson object.
Activity
BibMartin commentedon Feb 29, 2016
Hi @mattwg ,
thanks for your feedback and engagement.
It seems @om-henners is working on this (see #376).
For short term concerns, you can get a first workaround (not perfect though) in http://nbviewer.jupyter.org/gist/BibMartin/4b9784461d2fa0d89353 But this solution is less serious as @om-henners's implementation.
mattwg commentedon Mar 1, 2016
Hi Martin - thanks for the pointers I will take a look - and make sure I
follow #376 #376.
Matt
On Mon, Feb 29, 2016 at 3:04 AM, Martin Journois notifications@github.com
wrote:
Conengmo commentedon Oct 15, 2018
I think the
GeoJsonTooltipclass adds the functionality requested in this issue. It's available since 0.6.0. It doesn't work with theMap.choroplethmethod easily though, users have to manually get theGeoJsonorTopoJsonobject created byMap.choroplethand add theirGeoJsonTooltipto that.Closing this one.
jtbaker commentedon Oct 15, 2018
@Conengmo have you had a chance to look at #964?
Conengmo commentedon Oct 15, 2018
Ah you're right, I'm mixing up tooltips and popups. Reopening. When we finish your (upcoming) PR, this can be closed.
I have looked at your issue, but not good enough yet for a reply. I'm flagging it so I'll remember to do that soon.
araichev commentedon Oct 18, 2018
@Conengmo , regarding your comment
could you elaborate on it with an example illustrating how to add a tooltip to a choropleth?
I'm trying to do that exact thing and failing.
jtbaker commentedon Oct 19, 2018
@araichev, are you on the 0.6.0 release?
Check the docstring for
GeoJsonTooltipto reference its functionality with thehelpcommand, it covers the functionality pretty well.I have a a notebook example in my geojsonmarkers PR (not yet merged) that demonstrates it how the
GeoJsonTooltipcan be used. The marker argument is not yet active (I need to fix a few things) but the tooltipping will work the same way for a Choropleth/Polygon map.You can see it here: https://nbviewer.jupyter.org/github/jtbaker/folium/blob/geojsonmarker/examples/GeoJsonMarkersandTooltips.ipynb
araichev commentedon Oct 19, 2018
Thanks, @jtbaker .
I'm starting to understand, but am not all the way there yet.
Yes, i am on the 0.6.0 release.
I can create a choropleth with my tiles, GeoJSON layer, and colorscale.
I can create a tooltip on a copy of the original GeoJSON layer like you do in your notebook.
But how do i replace the choropleth GeoJSON layer with the second one that has the tooltip and still keep the choropleth colorscale?
Or am i going about this wrong?
jtbaker commentedon Oct 19, 2018
This conditional styling is done using the
style_functionargument inGeoJson. It takes a function as an an argument, which will evaluate on each feature in the dataset, and return a value based on the logic you give it. For simple fill colors, its easiest to pass a lambda function and query the object properties directly.Here's the example in the official documentation (check cells 9 through 13 or so): https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/GeoJSON_and_choropleth.ipynb
I think it is just more straightforward to query directly against the value instead of creating a new series/dict, just remember you have to pass through the
propertieskey to get to your actual key value.branca, a sibling offoliumthat you should have as well makes it easier to cook up linear and step colorscales with the use of d3.Some examples here:
https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Colormaps.ipynb
Check out the
/examplesdirectory on the main master branch for more usages and examples on how to work with the api. You can view them with output rendered on NBviewer: https://nbviewer.jupyter.org/github/python-visualization/folium/tree/master/examples/Hope this helps, let me know if you have any other questions!
Conengmo commentedon May 23, 2020
This issue is ancient! We now have a
GeoJsonPopupclass so this can be closed.aSipiere commentedon Jun 1, 2020
@Conengmo Actually adding a geojsonpopup to a geojson based choropleth map doesn't work. It gives
TypeError: You cannot add a GeoJsonPopup to anything other than a GeoJson or TopoJson object.Conengmo commentedon Jun 2, 2020
@aSipiere you can access the
GeoJsonobject created by theChoroplethclass like this:aSipiere commentedon Jun 2, 2020
Ah! Thanks I'd been trying to work this out all day.