如何从地图上 folium.featuregroup 内的 folium.Choropleth 中删除粗体蓝色轮廓颜色?
How to remove bold blue outline color from folium.Choropleth within an folium.featuregroup on the map?
我有以下名为结果的地理数据框:
调用results.explore()
将产生以下传单:
我的想法是使用 Featuregroups 和 Choropleth 创建 4 个不同的层,其中我想查看站点位置对每个区域内的总公里数有什么类型的影响。我要比较的变量是:T*_depot_0
、2_depots
、3_depots
和 4_depots
。我想在每一层中使用 fill_color OrRd,以便用较深的红色区分高值,用较浅的 orange/yellow 区分较低的值。通过图层控制,它可以点击不同的 Choropleth 并查看不同的站点在每个区域内的总行程距离上的差异。
我的代码:
def add_depot_markers_featuregroup(depot_amount, featuregroup):
for i in range(len(depots_locations)):
if i > depot_amount:
break
folium.Marker(
[depots_locations[i].y, depots_locations[i].x],
popup="Depot_{0}".format(i+1),
icon=folium.Icon(color='cadetblue', icon='solid fa-bicycle', prefix='fa')).add_to(featuregroup)
result_map = folium.Map(location=lat_long_groningen, zoom_start=11, tiles=None)
layer_depot_1 = folium.FeatureGroup(name="1 depot", overlay=False).add_to(result_map)
layer_depot_2 = folium.FeatureGroup(name="2 depots", overlay=False).add_to(result_map)
layer_depot_3 = folium.FeatureGroup(name="3 depots", overlay=False).add_to(result_map)
layer_depot_4 = folium.FeatureGroup(name="4 depots", overlay=False).add_to(result_map)
fs=[layer_depot_1, layer_depot_2, layer_depot_3, layer_depot_4]
for i in range(len(fs)):
add_depot_markers_featuregroup(i, fs[i])
depot_column_name = ""
if i == 0:
depot_column_name = "T*_depot_{0}".format(i)
else:
depot_column_name = "{0}_depots".format(i+1)
bins = list(results[depot_column_name].quantile([0, 0.25, 0.5, 0.75, 1]))
choropleth = folium.Choropleth(
results,
data=results,
key_on='feature.properties.Postcode',
columns=["Postcode", depot_column_name],
fill_color="OrRd",
fill_opacity = 0.8,
line_opacity = 0,
line_weight=1,
bins=bins,
legend_name = "T* per postalcode area based on depot {0}".format(i+1),
name="T* of {0} depot per Postalcode area".format(i+1)).geojson.add_to(fs[i])
geojson1 = folium.GeoJson(data=results,
name="tooltip " + depot_column_name,
tooltip=folium.GeoJsonTooltip(fields=['Postcode', "Deliveries", "Area (km2)", "Number of cyclists", "Beardwood approx", depot_column_name], labels=True, sticky=True)
).add_to(choropleth)
# folium.TileLayer('cartodbdark_matter',overlay=True,name="dark mode").add_to(result_map)
folium.TileLayer('cartodbpositron',overlay=True, control=False, name="T*").add_to(result_map)
folium.LayerControl(collapsed=False).add_to(result_map)
result_map.save("lastmile.html")
result_map
所以,好消息是分层工作。坏消息是我在地图上的不同多边形和多边形之间有非常粗的蓝线,我不知道如何change/remove。我试过设置 Choropleth 的 line_color="black"
,但这没有用。
如何 remove/change/minimize 每个特征组中的粗体蓝色轮廓颜色?
由于没有提供数据,我引用official sample。多边形轮廓的线条装饰由样式函数定义。该示例定义了颜色、线宽和虚线。线宽由 'weight'.
设置
import json
import requests
import folium
url = ("https://raw.githubusercontent.com/python-visualization/folium/main/examples/data")
us_states = f"{url}/us-states.json"
geo_json_data = json.loads(requests.get(us_states).text)
m = folium.Map([43, -100], zoom_start=4)
folium.GeoJson(
geo_json_data,
style_function=lambda feature: {
"fillColor": "#ffff00",
"color": "black",
"weight": 2,
"dashArray": "5, 5",
},
).add_to(m)
m
我有以下名为结果的地理数据框:
调用results.explore()
将产生以下传单:
我的想法是使用 Featuregroups 和 Choropleth 创建 4 个不同的层,其中我想查看站点位置对每个区域内的总公里数有什么类型的影响。我要比较的变量是:T*_depot_0
、2_depots
、3_depots
和 4_depots
。我想在每一层中使用 fill_color OrRd,以便用较深的红色区分高值,用较浅的 orange/yellow 区分较低的值。通过图层控制,它可以点击不同的 Choropleth 并查看不同的站点在每个区域内的总行程距离上的差异。
我的代码:
def add_depot_markers_featuregroup(depot_amount, featuregroup):
for i in range(len(depots_locations)):
if i > depot_amount:
break
folium.Marker(
[depots_locations[i].y, depots_locations[i].x],
popup="Depot_{0}".format(i+1),
icon=folium.Icon(color='cadetblue', icon='solid fa-bicycle', prefix='fa')).add_to(featuregroup)
result_map = folium.Map(location=lat_long_groningen, zoom_start=11, tiles=None)
layer_depot_1 = folium.FeatureGroup(name="1 depot", overlay=False).add_to(result_map)
layer_depot_2 = folium.FeatureGroup(name="2 depots", overlay=False).add_to(result_map)
layer_depot_3 = folium.FeatureGroup(name="3 depots", overlay=False).add_to(result_map)
layer_depot_4 = folium.FeatureGroup(name="4 depots", overlay=False).add_to(result_map)
fs=[layer_depot_1, layer_depot_2, layer_depot_3, layer_depot_4]
for i in range(len(fs)):
add_depot_markers_featuregroup(i, fs[i])
depot_column_name = ""
if i == 0:
depot_column_name = "T*_depot_{0}".format(i)
else:
depot_column_name = "{0}_depots".format(i+1)
bins = list(results[depot_column_name].quantile([0, 0.25, 0.5, 0.75, 1]))
choropleth = folium.Choropleth(
results,
data=results,
key_on='feature.properties.Postcode',
columns=["Postcode", depot_column_name],
fill_color="OrRd",
fill_opacity = 0.8,
line_opacity = 0,
line_weight=1,
bins=bins,
legend_name = "T* per postalcode area based on depot {0}".format(i+1),
name="T* of {0} depot per Postalcode area".format(i+1)).geojson.add_to(fs[i])
geojson1 = folium.GeoJson(data=results,
name="tooltip " + depot_column_name,
tooltip=folium.GeoJsonTooltip(fields=['Postcode', "Deliveries", "Area (km2)", "Number of cyclists", "Beardwood approx", depot_column_name], labels=True, sticky=True)
).add_to(choropleth)
# folium.TileLayer('cartodbdark_matter',overlay=True,name="dark mode").add_to(result_map)
folium.TileLayer('cartodbpositron',overlay=True, control=False, name="T*").add_to(result_map)
folium.LayerControl(collapsed=False).add_to(result_map)
result_map.save("lastmile.html")
result_map
所以,好消息是分层工作。坏消息是我在地图上的不同多边形和多边形之间有非常粗的蓝线,我不知道如何change/remove。我试过设置 Choropleth 的 line_color="black"
,但这没有用。
如何 remove/change/minimize 每个特征组中的粗体蓝色轮廓颜色?
由于没有提供数据,我引用official sample。多边形轮廓的线条装饰由样式函数定义。该示例定义了颜色、线宽和虚线。线宽由 'weight'.
设置import json
import requests
import folium
url = ("https://raw.githubusercontent.com/python-visualization/folium/main/examples/data")
us_states = f"{url}/us-states.json"
geo_json_data = json.loads(requests.get(us_states).text)
m = folium.Map([43, -100], zoom_start=4)
folium.GeoJson(
geo_json_data,
style_function=lambda feature: {
"fillColor": "#ffff00",
"color": "black",
"weight": 2,
"dashArray": "5, 5",
},
).add_to(m)
m