Skip to content

Heatmap gradient color in folium.plugins.HeatMap is not documented. #2051

Closed

Description

@defending1

Describe the bug

The documentation for folium.plugins.HeatMap mentions that default gradient is None, but I found that Folium seems using the standard gradient color from leaflet, which from the source code is defined as (see leaflet_heat.min.js, or the dependency simpleheat.js):

defaultGradient:{.4:"blue",.6:"cyan",.7:"lime",.8:"yellow",1:"red"}

To me is also not clear from the js code which colors the gradient uses before 0.4. I tried to understand it looking at simpleheat.js function (grad), since the minified version should come from here. One comment in this function says "create a 256x1 gradient that we'll use to turn a grayscale heatmap into a colored one". So should I assume that the gradient in 0 starts from black?

Additional context

Like user from issue #1579, I was trying to replicate the default gradient to build a colormap for the heatmap plot, and it was not obvious to figure out that the gradient color used could be defined in the leaflet.js file.

Possible solutions

Passing defaultGradient as object for folium.plugins.HeatMap, even if it will do nothing because the default is still defined in the leaflet.js code, it could be useful for future users.

Activity

  1. Conengmo commented on Dec 14, 2024

    @Conengmo
    Member

    Thanks for reporting this missing information! I understand you would like to be able to know the default gradient without having to dive into the underlying Javascript code.

    The simplest thing would be to just add that default gradient to the docstring. We already have an example there, we can replace it with the default gradient.

    I wouldn't want to do it as a default argument to the class, because mutable types are not recommended as default arguments.

  2. Conengmo commented on Dec 14, 2024

    @Conengmo
    Member

    @defending1 maybe you can check out https://github.com/python-visualization/folium/pull/2052/files see if this addresses your issue?

  3. defending1 commented on Dec 14, 2024

    @defending1
    Author

    Yes good idea. This solves, thanks.

  4. Conengmo commented on Dec 14, 2024

    @Conengmo
    Member

    Great, thanks!

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