Skip to content

Popups on Choropleth Map #375

Closed
Closed

Description

@mattwg

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!

Matt

Activity

  1. BibMartin commented on Feb 29, 2016

    @BibMartin
    Contributor

    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.

  2. mattwg commented on Mar 1, 2016

    @mattwg
    Author

    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:

    Hi @mattwg https://github.com/mattwg ,

    thanks for your feedback and engagement.
    It seems @om-henners https://github.com/om-henners is working on this
    (see #376 #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
    https://github.com/om-henners's implementation.

    —
    Reply to this email directly or view it on GitHub
    #375 (comment)
    .

  3. added
    work in progress
    on Apr 22, 2018
  4. Conengmo commented on Oct 15, 2018

    @Conengmo
    Member

    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.

    Closing this one.

  5. removed
    work in progress
    on Oct 15, 2018
  6. jtbaker commented on Oct 15, 2018

    @jtbaker
    Contributor

    @Conengmo have you had a chance to look at #964?

  7. Conengmo commented on Oct 15, 2018

    @Conengmo
    Member

    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.

  8. araichev commented on Oct 18, 2018

    @araichev

    @Conengmo , regarding your comment

    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.

  9. jtbaker commented on Oct 19, 2018

    @jtbaker
    Contributor

    @araichev, are you on the 0.6.0 release?

    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.

    You can see it here: https://nbviewer.jupyter.org/github/jtbaker/folium/blob/geojsonmarker/examples/GeoJsonMarkersandTooltips.ipynb

  10. araichev commented on Oct 19, 2018

    @araichev

    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?

  11. jtbaker commented on Oct 19, 2018

    @jtbaker
    Contributor

    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.

    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 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.

    Some examples here:
    https://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Colormaps.ipynb

    Check out the /examples directory 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!

  12. Conengmo commented on May 23, 2020

    @Conengmo
    Member

    This issue is ancient! We now have a GeoJsonPopup class so this can be closed.

  13. aSipiere commented on Jun 1, 2020

    @aSipiere

    @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.

  14. Conengmo commented on Jun 2, 2020

    @Conengmo
    Member

    @aSipiere you can access the GeoJson object created by the Choropleth class like this:

    choropleth = folium.Choropleth()
    GeoJsonPopup().add_to(choropleth.geojson)
    
  15. aSipiere commented on Jun 2, 2020

    @aSipiere

    Ah! Thanks I'd been trying to work this out all day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions