#399·folium

Adding a colormap to a Layer or FeatureGroup

Author: eddiesCreated Mar 23, 2016Updated Jan 6, 2026
Labelsenhancement

Hopefully, this is just a case of I'm-Doing-It-Wrong.

I'd like to be able to associate a colormap with a specific layer (e.g. GeoJson or TopoJson layer), independently of say, another layer of just markers or just a different choropleth layer. This way, if I deselect a layer in the LayerControl, both the GeoJson layer and the associated colormap go away (which also lets me have a separate colormap per Geo/TopoJson layer).

I've tried adding the colormap to the layer itself as well as adding both the layer and colormap to a FeatureGroup, but neither of these approaches seem to work.

Have a look at: https://github.com/eddies/folium/blob/59f88bca397a600b138abfc21591373ac3a66a78/tests/test_colormap_layer.py for an example (sorry, it's not a Jupyter notebook--long story about problems w/ Jupyter and virtualenvs)

Source: python-visualization/folium