根据标记颜色过滤Folium Map [英] Filter Folium Map based on marker color

查看:58
本文介绍了根据标记颜色过滤Folium Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在映射具有称为"marker_color"的行的标记.指示红色",黄色"和绿色".基于其他列值.如何在地图的一角添加过滤器选项,使我只能根据颜色显示一个,两个,全部或不显示任何标记?基本上,有三个可单击的单选选项来呈现三个彩色标记.

I am mapping markers that have a row called "marker_color" indicating "red", "yellow", and "green" based on other column values. How can I add a filter option to the corner of my map that will allow me to only show one, two, all, or none of the markers based on color? Basically, three clickable radio options to render the three colored markers.

当前,我正在从sales_colored数据框中映射所有标记,

Currently, I am mapping all markers like so from my sales_colored dataframe:

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 的词典来存储颜色).您可以创建如下代码:

If you want to add checkbox for each color, you can use a folium.FeatureGroup(). You need first to collect all unique value in the column sales_colored["marker_color"] and you create one FeatureGroup for each color (I use a dictionnary called features to store the colors). You can create a code like this :

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

这篇关于根据标记颜色过滤Folium Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆