在Folium Map中添加标题或文本 [英] Adding a Title or Text to a Folium Map

查看:1218
本文介绍了在Folium Map中添加标题或文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法在python的大叶草地图上添加标题或文本?

I'm wondering if there's a way to add a title or text on a folium map in python?

我要显示8张地图,我希望用户无需单击标记即可知道他们正在查看的地图。我试图添加地图图像,但由于我的信誉评分不够高而无法添加。

I have 8 maps to show and I want the user to know which map they're looking at without having to click on a marker. I attempted to add an image of the map, but couldn't because I don't have high enough reputation score.

我的代码:

#marker cluster
corpus_chris_loc = [27.783889, -97.510556]

harvey_avg_losses_map = folium.Map(location = corpus_chris_loc, zoom_start = 5)

marker_cluster = MarkerCluster().add_to(harvey_avg_losses_map)

#inside the loop add each marker to the cluster
for row_index, row_values in harvey_losses.iterrows():

    loc = [row_values['lat'], row_values['lng']]
    pop = ("zip code: " + str(row_values["loss_location_zip"]) + "\nzip_avg: " + "$" + str(row_values['zip_avg'])) #show the zip and it's avg
    icon = folium.Icon(color='red')
    marker = folium.Marker(
        title = "Harvey: " + "$" + str(row_values['harvey_avg']),
        location = loc, 
        popup = pop,
        icon=icon) 

    marker.add_to(marker_cluster)


#save an interactive HTML map by calling .save()

harvey_avg_losses_map.save('../data/harveylossclustermap.html')

harvey_avg_losses_map[map of hurricane harvey insurance claims][1]


推荐答案

您当然可以添加

例如:

import folium

loc = 'Corpus Christi'
title_html = '''
             <h3 align="center" style="font-size:16px"><b>{}</b></h3>
             '''.format(loc)   

m = folium.Map(location=[27.783889, -97.510556],
               zoom_start=12)

m.get_root().html.add_child(folium.Element(title_html))

m.save('map-with-title.html')
m

这篇关于在Folium Map中添加标题或文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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