首页 > 解决方案 > 如何增加 python folium 中的弹出窗口宽度?

问题描述

我正在遍历我的数据框,使用每列中的每个值来添加弹出窗口。但是弹出窗口的宽度太小,因此一个值显示在多行中。

这就是我的代码的样子:

c = folium.Map(
    location=[12.323, 146.029326],
    zoom_start=14
)
for row in df.itertuples():
    name = getattr(row, "name")
    age  = getattr(row, "age")
    folium.Marker(
        location = location,
        popup=folium.Popup(f"""name= {name} <br>
                               age = {age} <br>
                            """),
        icon=plugins.BeautifyIcon(
            border_color = color,
            border_width = 2,
            text_color   = 'black'
        )
    ).add_to(c)

我想要每个列值有足够的空间。我怎样才能做到这一点?

标签: pythonfolium

解决方案


您可以使用对象的max_width参数Popup。您可以指定一个数字,该数字取决于名称行中的字符数,如下所示:

popup=folium.Popup(f"""name= {name} <br>
                       age = {age} <br>
                    """, max_width=len(f"name= {name}")*20),

推荐阅读