gpt4 book ai didi

python - 如何在 folium.circle map python 中的每个圆上添加标签

转载 作者:太空宇宙 更新时间:2023-11-04 09:42:44 25 4
gpt4 key购买 nike

嘿嘿我正在尝试将标签添加到 folium.circle map 中,但由于某些原因它不起作用,任何人都可以提供帮助,这是我的 map 脚本:

import folium
# Make an empty map
m = folium.Map(location=[59.911491, 10.757933], tiles="Mapbox Bright", zoom_start=5)
# I can add marker one by one on the map
hc =list(rf_map["General HC Type"])
def color_producer(hc_type):
if hc_type =="Oil Fields":
return 'green'
elif hc_type =="Oil & Gas Fields":
return 'deeppink'
else:
return 'red'
for i,hc_map in zip(range(0,len(rf_map)),hc):
folium.Circle(
location=[rf_map.iloc[i]['Latitude Dec Deg'],rf_map.iloc[i]['Longitude Dec Deg']],
popup=rf_map.iloc[i]['Field Name'],
radius=rf_map.iloc[i]['Oil Recovery PP Factor']*300,
fill=True,
fill_color=color_producer(hc_map),
color=color_producer(hc_map),
fill_opacity=0.7,
label=rf_map.iloc[i]["Field Name"]
).add_to(m)
m.save('map.html')

最佳答案

嘿嘿。你想在圆圈的中间(或其他地方)有弹出标签或只是一个文本吗?

弹窗:

要为圆形对象制作弹出框架,您只需要使用 add_child 方法。代码将如下所示:

m = folium.Map([60, 10], tiles='Mapbox Bright', zoom_start=5)
folium.Circle([60, 10], 150000, fill=True).add_child(folium.Popup('My name is Circle')).add_to(m)

输出:

enter image description here

常规文本解决方案

如果您发现弹出式解决方案不适合您的需求,那么您可以在 map 上放置一个文本对象。文本的坐标可以与圆心并置。

例如:

import folium
from folium.features import DivIcon


text = 'Test'
circle_lat = 60
circle_lon = 10

m = folium.Map([60, 10], tiles='Mapbox Bright', zoom_start=5)
folium.Circle([circle_lat, circle_lon], 150000, fill=True).add_child(folium.Popup('My name is Circle')).add_to(m)
folium.map.Marker(
[circle_lat + 0.5, circle_lon - 1.6],
icon=DivIcon(
icon_size=(150,36),
icon_anchor=(0,0),
html='<div style="font-size: 24pt">%s</div>' % text,
)
).add_to(m)
m

该代码的输出是:

enter image description here

我找到了文本 here 的解决方案.我希望正确理解问题并且示例有助于解决您的问题。如果您有任何疑问或我误解了问题中的某些内容,请告诉我。

关于python - 如何在 folium.circle map python 中的每个圆上添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51039161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com