我正在映射具有基于其他列值的名为“ marker_color”的行,指示“红色”,“黄色”和“绿色”的标记。如何在地图的一角添加过滤器选项,使我只能根据颜色显示一个,两个,全部或不显示任何标记?基本上,三个可单击的单选选项可呈现三个彩色标记。
目前,我正在从sales_colored数据框中映射所有标记,如下所示:
basemap2 = generateBaseMap()
for index, row in sales_colored.iterrows():
folium.Circle([row['Latitude'], row['Longitude']],
radius=200, color=row['marker_color'], fill_color=row['marker_color']).add_to(basemap2)
basemap2
如果要为每种颜色添加复选框,则可以使用folium.FeatureGroup()
。您需要首先收集该列中的所有唯一值,sales_colored["marker_color"]
然后为每种颜色创建一个FeatureGroup(我使用一个字典features
来存储颜色)。您可以创建如下代码:
features = {}
for row in pd.unique(sales_colored["marker_color"]):
features[row] = folium.FeatureGroup(name=row)
for index, row in sales_colored.iterrows():
circ = folium.Circle([row['Latitude'], row['Longitude']],
radius=200, color=row['marker_color'], fill_color=row['marker_color'])
circ.add_to(features[row['marker_color']])
for row in pd.unique(sales_colored["marker_color"]):
features[row].add_to(basemap2)
folium.LayerControl().add_to(basemap2)
basemap2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句