Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Legend on a Folium map

Tags:

python

folium

The Folium documentation is incomplete at this time: https://folium.readthedocs.io/en/latest/

According to the index of the incomplete docs Legends and Layers are, or will be supported. I've spent some time looking for examples on the web but have found nothing so far. If anyone has any idea how to create these things, or can point me to a document or tutorial I would be most grateful.

like image 374
sparrow Avatar asked May 26 '16 16:05

sparrow


2 Answers

You can add a legend quite easily;

#specify the min and max values of your data
colormap = branca.colormap.linear.YlOrRd_09.scale(0, 8500)
colormap = colormap.to_step(index=[0, 1000, 3000, 5000, 8500])
colormap.caption = 'Incidents of Crime in Victoria (year ending June 2018)'
colormap.add_to(world_map)

You can see my complete example here;

Folium Map with legend example

like image 53
Harley Avatar answered Sep 18 '22 15:09

Harley


Folium now has a way to add an image easily with version 0.15.

from folium.plugins import FloatImage
image_file = 'image.PNG'

FloatImage(image_file, bottom=0, left=86).add_to(mymap)
like image 26
sparrow Avatar answered Sep 22 '22 15:09

sparrow