Reputation: 454
I'm using Python only and would like to adjust the heatmap's maximum opacity. As you can see in the image below, the base map is quite invisible. I want to see more of the base map. How do I adjust the parameters in the HeatMap
so that I can increase the opacity of the heatmap layer using only Python?
it's quite the same problem in here, but it uses leaflet.js and the solution is using CSS, not Python. Anyway, here's my code I used to produce the map.
import folium
from folium import plugins
from folium.plugins import HeatMap
import pandas as pd
df = pd.read_csv("the_data.csv") # the data contains lat and long columns, I can't share the data...
coords = [(lat, lng) for lat, lng in zip(restaurants[0].lat.to_list(), restaurants[0].lon.to_list())]
m = folium.Map([-6.204725,106.847009], tiles="CartoDB dark_matter", zoom_start=14)
HeatMap(coords,
min_opacity=0.4,
max_val = 0.5,
gradient={.2: '#482d61', .5:"#5aa7d6", 1: '#fffaad'}).add_to(folium.FeatureGroup(name='Heat Map').add_to(m))
folium.LayerControl().add_to(m)
m.save("heatmap.html")
Upvotes: 0
Views: 2949
Reputation: 131
Have you tried with other tiles and other gradient colors ?
The current tile option you are using don't seem useful if you want urban details. I suggest you use 'OpenStreetMap'
or 'Cartodb Positron'
with regular gradient colors.
Is gives something like this, where you can see some urban informations :
m = folium.Map([48., 5.], tiles='OpenStreetMap', zoom_start=6)
HeatMap(data, min_opacity=0.4.add_to(m)
If you want to stick with the tile you are using, I can suggest you to use the blur parameter.
Exemple with default blur = 15
m = folium.Map([48., 5.], tiles='CartoDB dark_matter', zoom_start=6)
HeatMap(data, min_opacity=0.4, blur = 15, gradient={.2: '#482d61', .5:"#5aa7d6", 1: '#fffaad'}).add_to(folium.FeatureGroup(name='Heat Map')).add_to(m)
Example with blur = 30
m = folium.Map([48., 5.], tiles='CartoDB dark_matter', zoom_start=6)
HeatMap(data, min_opacity=0.4, blur = 30, gradient={.2: '#482d61', .5:"#5aa7d6", 1: '#fffaad'}).add_to(folium.FeatureGroup(name='Heat Map')).add_to(m)
Of course, the bigger the blur parameter, the more difficult it can be to interpret the data. As I don't know your objective, I'll let you decide what best suits you.
Upvotes: 2