Skip to content

Gradient parameter in heatmap in newest version can't work-'float' object has no attribute 'split' #2098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wybert opened this issue Feb 28, 2025 · 2 comments · Fixed by #2100
Assignees

Comments

@wybert
Copy link

wybert commented Feb 28, 2025

The gradient parameter in heatmap seems can't work in version since0.19.0. To reproduce, use the following code, or in colab

data = (
    np.random.normal(size=(100, 3)) * np.array([[1, 1, 1]]) + np.array([[48, 5, 1]])
).tolist()

import folium
from folium.plugins import HeatMap

m = folium.Map([48.0, 5.0], zoom_start=6)

HeatMap(data,
        gradient = {0.4: "blue", 0.6: "cyan",
                    0.7: "lime", 0.8: "yellow", 1: "red"}
        ).add_to(m)

m

In newest version 0.19.4 the error is show below,

AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.11/dist-packages/IPython/core/formatters.py](https://localhost:8080/#) in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

13 frames
<template> in macro(l_1_this, l_1_kwargs)

[/usr/local/lib/python3.11/dist-packages/folium/utilities.py](https://localhost:8080/#) in camelize(key)
    347     'variableName'
    348     """
--> 349     return "".join(x.capitalize() if i > 0 else x for i, x in enumerate(key.split("_")))
    350 
    351 
AttributeError: 'float' object has no attribute 'split'
<folium.folium.Map at 0x7dff47d57990>
@wybert
Copy link
Author

wybert commented Feb 28, 2025

It can be address by,

HeatMap(data,
        gradient = {"0.1": "blue", "0.6": "cyan",
                    "0.7": "lime", "0.8": "yellow", "1": "red"}
        ).add_to(m)

However, it seems not consistent with the document,

gradient (dict, default None) – Color gradient. Defaults to {.4: “blue”, .6: “cyan”, .7: “lime”, .8: “yellow”, 1: “red”}

@hansthen
Copy link
Collaborator

hansthen commented Mar 1, 2025

Let me have a look at it. @wybert using string keys, does it do what you expect it to do?

@hansthen hansthen self-assigned this Mar 1, 2025
hansthen added a commit that referenced this issue Mar 1, 2025
@hansthen hansthen linked a pull request Mar 1, 2025 that will close this issue
hansthen added a commit that referenced this issue Mar 13, 2025
* Fix numeric keys in arguments

Closes #2098

* add a test case

---------

Co-authored-by: Conengmo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants