I have a few choropleth maps in one Leaflet map using folium. However, in my output, my legends all congregate underneath one another and on one side where it blocks the 'control zoom' icon.
Is there a way to alter the location of my legend(s) or only have one activated at a time?
Image of result:
Code of
NYC_coords = (40.7, -73.8) # specifying our location data
flm_map = flm.Map(location = NYC_coords, zoom_start = 10.3, tiles = 'cartodbpositron', zoom_control = True)# zoom level, tiles
dangerous_int = flm.FeatureGroup(name='Dangerous Intersections', control=True)
neighborhoods = flm.FeatureGroup(name = 'Neighborhoods', control = True)
dscore = flm.Choropleth(
geo_data = nbhood, # json file, contains geometries
data = nbhood_df, # dataframe used
name = 'Danger Score',
columns = ['Neighborhood','Danger Score Avg'], # columns to refer to for choropleth colors
key_on = 'feature.properties.Neighborhood', # the key we are looking for to base
fill_color = 'Reds', # color ramp
fill_opacity = 0.7,
line_opacity = 0.5,
highlight = True,
popup = flm.GeoJsonPopup(fields = ['Neighborhood', 'Danger Score Avg']),
legend_name = 'Average Danger Score',
smooth_factor = 0.2).add_to(flm_map)
motor_inj = flm.Choropleth(
geo_data = nbhood, # json file, contains geometries
data = nbhood_df, # dataframe used
name = 'Motor Injuries',
columns = ['Neighborhood','Motor Vehicle Injuries'], # columns to refer to for choropleth colors
key_on = 'feature.properties.Neighborhood', # the key we are looking for to base
fill_color = 'BuPu', # color ramp
fill_opacity = 0.7,
line_opacity = 0.5,
popup = flm.GeoJsonTooltip(fields = ['Neighborhood', 'Motor Vehicle Injuries']),
highlight = True,
legend_name = 'Motor Vehicle Injuries(total)',
smooth_factpr = 0.2,
show = False).add_to(flm_map)
flm.LayerControl('topright', collapsed = True).add_to(flm_map)
display(flm_map)