Cusomizing the colorbar tick labels in a folium map (using branca colormap plugin)
See original GitHub issueHi,
I am using folium map for making a “heat map”-like plot on an Open Street Map. I want to plot some GPS Lat/Lon data on a map, but the color of each point must represent the accuracy estimation of the GPS receiver at the point. For this reason, I use a logarithmic color mapping (using branca plugin) and I add the color map to the folium map using add_child() function. I’ve almost completed the code but the only problem is that I can’t change the tick labels of the colorbar. It shows the indexes that I’ve used for branca colormap, but I would rather customize the tick labels in another way.
Here is my code:
import folium.plugins
import branca
import branca.colormap as cm
fname = 'test_colorbar.html'
# Load Folium map object, working with Open Street Map and zoom of 17
# Note that 17-zoom is maximum possible zoom
base_lat = 50.682294344
base_lon = 10.939628989
f_map = folium.Map(location=[base_lat,base_lon], tiles="OpenStreetMap", zoom_start=17)
lat_ = [50.6823, 50.6822, 50.6821, 50.6820, 50.6819]
lon_ = [10.9396291, 10.9396279, 10.9396269, 10.9396265, 10.9396261]
acc_ = [11.0,44.5,149.9,319.1,540.0,752.6]
colormap = cm.LinearColormap(colors=['darkblue', 'blue', 'cyan', 'yellow', 'orange', 'red'],
index=[0, 25, 62.5, 156.25, 390.6, 1000], vmin=0, vmax=1000,
caption='Total Standard deviation at the point[mm]')
fg = folium.FeatureGroup(name=fname.split('.')[0])
for pt in range(len(lat_)):
color = colormap(acc_[pt])
fg.add_child(folium.CircleMarker(location=[lat_[pt],lon_[pt]],
radius=6,
fill=True,
color=color,
fill_color=color))
f_map.add_child(fg)
f_map.add_child(colormap)
# Save the result as an HTML file
print('Saving the map file...')
f_map.save(fname)
This code delivers the following result:
but I want the same colorbar with customized tick labels [0,1,10,100,1000] instead of [0, 25, 62.5, 156.25, 390.6, 1000].
Also I am using folium 0.10.0 in Jupyter Notebook on Mac OSX.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
We just merged https://github.com/python-visualization/branca/pull/113, which implements a parameter to set custom tick labels. It will be included in the next branca release, which will be 0.6.0, date yet undefined. Thanks everybody for the input on this topic and @kota7 for the PR.
It would be great to have the nonlinear colorbar feature (ie. ‘ticklabels’) available per @markhudson42 example. I need a colorbar for an exponential distribution and can’t find a way to get it to look right.