2

Hi I have created a simple heatmap using folium and would like to adjust the gradient/color of the heatmap. I have tried to play with the gradient feature in folium by using the code shown below

import folium
from folium import plugins
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os

data =[[    40.7726,    -73.9568,   1900.    ],
       [    40.7785,    -73.9556,   3200.    ],
       [    40.7216,    -73.9809,   5800.    ],
       [    40.7384,    -73.9848,   2900.    ],
       [    40.7678,    -73.9915,   3312.    ],
       [    40.7659,    -73.9574,   2600.    ],
       [    40.7092,    -74.0137,   4299.    ],
       [    40.7384,    -73.982 ,   5750.    ],
       [    40.7312,    -73.9896,   3595.    ]]

m = folium.Map([40.7726,    -73.9568], 
               control_scale = True, zoom_start=11)

plugins.HeatMap(data, radius = 20, min_opacity = 0.1, max_val = 50,gradient={.6: 'blue', .98: 'lime', 1: 'red'}).add_to(m)

However, the effects isn't what I expected it to be. When plotting on a heatmap I will get something like the image shown below

enter image description here

For instance maybe the range to get Red requires a cluster of 20 but I would like to change this to maybe a cluster of 10 in order to be red. Is this possible with Folium?

Additionally, I would like to also plot the heatmap according to it's weights. For example, I can have two points one with a weight of 1900 and the other with 5800, I would like the 5800 to glow red while the weight of 1900 is yellow.

1 Answer 1

1

Your use of the feature gradient in

plugins.HeatMap(data, radius = 20, min_opacity = 0.1, max_val = 50,gradient={.6: 'blue', .98: 'lime', 1: 'red'}).add_to(m)

is correct but there is bug in Leaflet on which Folium is relying on:

https://github.com/python-visualization/folium/issues/496

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.