如何更改folium popup的背景颜色?

时间:2018-03-01 13:35:23

标签: python python-3.x leaflet folium

我正在使用folium进行地图可视化。你知道如何将弹出窗口的背景颜色从白色更改为不同的颜色吗?

从这里How can I change the background color of a Leaflet popup?我知道这可以直接在Leaflet上找到,但我找到了与Folium有关的任何内容!

谢谢!

1 个答案:

答案 0 :(得分:0)

选项1(手动):

使用编辑器软件打开.html文件,并在<style>标记中粘贴以下内容:.leaflet-popup-content-wrapper {background-color:black; color:white}

选项2(自动化):

创建地图并将其保存在path中。 然后使用BeautifulSoup

from bs4 import BeautifulSoup
path = 'your/path/map.html'
soup = BeautifulSoup(open(path), "html.parser")
head = soup.head
head.append(soup.new_tag('style', type='text/css'))
head.style.append(' .leaflet-popup-content-wrapper {background-color:black; color:white}')
with open(path, "w") as file: file.write(str(soup))