question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cusomizing the colorbar tick labels in a folium map (using branca colormap plugin)

See original GitHub issue

Hi,

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: image

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:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Conengmocommented, Nov 4, 2022

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.

1reaction
emskiphotocommented, May 25, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cusomizing the colorbar tick labels in a folium map (using ...
It shows the indexes that I've used for branca colormap, but I would rather customize the tick labels in another way.
Read more >
branca.colormap — branca 0.6.0 documentation - GitHub Pages
class branca.colormap. ... caption (str) – A caption to draw with the colormap. max_labels (int, default 10) – Maximum number of legend tick...
Read more >
Adding linear colorbar associated with markers on a folium map
You can create a colorbar with this code : import branca.colormap as cmp step = cmp.StepColormap( col_hex, vmin=1, vmax=15, caption='Color ...
Read more >
ego.tools.plots — eGo 0.3.4 documentation
[docs]def plot_storage_use(ego, filename, display): """Plot storage use by ... eTraGo and eDisGo results tiles: str Folium background map style `None` as ...
Read more >
Pyplot.Contourf And Branca Colormap Does Not Show The ...
Here is what I have Contourf plot in matplotlib using Python For plotting the. ... the colorbar tick labels in a folium map...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found