You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整folium弹窗宽度,使预格式化HTML弹窗内容每行完整展示

你可以通过显式声明folium.Popup实例并设置max_width参数调整弹窗宽度,即可避免内容意外折行,修改后的代码如下:

map = folium.Map(location=[new_df.Latitude.mean(), new_df.Longitude.mean()], zoom_start=12, control_scale=True,min_zoom=10,max_zoom=12)

for index, location_info in new_df.iterrows():
    # 自定义Popup,设置最大宽度为350,足够容纳你当前的单行字段内容
    popup = folium.Popup(location_info["String_for_Popup"], max_width=350)
    folium.Marker([location_info["Latitude"], location_info["Longitude"]], popup=popup, tooltip=location_info["Site_Description"]).add_to(map)

如果后续需要适配更长的内容,也可以把max_width调整为更高的数值,或者设置为"100%"让弹窗自动适配内容宽度。

内容的提问来源于stack exchange,提问作者RevolverOshawott

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 15:27:03