在 Folium 中,对于图例(legend),您需要手动创建一个 HTML 元素并将其添加到地图页面中
html
模块创建一个 HTML 图例元素:
from html import escape legend_html = ''' <!DOCTYPE html> <html> <head> <style> #map_legend {position: fixed; bottom: 50px; left: 50px; width: 150px; height: 90px; border:1px solid grey; z-index:9999; font-size:14px; background-color:white; } </style> <div id="map_legend"> <p><b>Legend</b></p> <p><i class="fa fa-map-marker fa-2x" style="color:green;"></i> Portland, OR</p> </div> </html> ''' with open("map_legend.html", "w") as f: f.write(legend_html)combined_map.html
文件,您将看到一个包含图例的地图。领取专属 10元无门槛券
手把手带您无忧上云