Choropleth legends being part of the layer
See original GitHub issuePlease add a code sample or a nbviewer link, copy-pastable if possible
This is how I created and added the folium.Choropleth layers to the folium.Map object (self.map is a default folium.Map object)
folium.Choropleth(geo_data=self.geo_json,
data=self.map_data,
columns=[self.CODE_COL,self.SCORE_COL],
key_on='feature.properties.' + self.code_name,
fill_color=self.color,
fill_opacity=0.6,
line_opacity=0.2,
bins=self.scale,
legend_name=self.legend_label,
name=name,
nan_fill_color='purple',
show=show).add_to(self.map)
This is how I added folium.LayerControl and saved the file
folium.LayerControl(collapsed=False).add_to(self.map)
self.map.save(self.out_file)
Problem description
I created a folium.Map with two folium.Choropleth objects added to it as overlays, so that someone viewing the .html file could choose which choropleth map they would like to see using the LayerControl. When the layers were deselected the choropleth layers were removed from the screen but the legend stayed.
I found this behaviour confusing as, when a choropleth layer was deselected the legend remained on the screen, I would expect the legends to belong to the layers on the map and appear and disappear as layers were selected/deselected.
Expected Output
The legends for a folium.Choropleth object should disappear when the folium.Choropleth layer is deselected from the layer control box.
Output of folium.__version__
0.7.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:14
- Comments:12 (1 by maintainers)
Top GitHub Comments
@julianaddison The Python method @kylenguyen245 mentioned does work in principle. Delete color_map children outside of the loop. Hope this helps.
@kylenguyen245 I sometimes delete the legend (color maps) because the numerical labels overlap one another. I often don’t use linear spacing for the bins. Do you know whether there’s a way to use fewer labels than there are bins to avoid overlapping labels (see picture)?
Turns out this is actually a duplicate of https://github.com/python-visualization/folium/issues/450