How to fix Folium Popup size in Folium 0.12

Viewed 165

I am creating a Folium map with markers and popups. At the moment they are just static strings, however when I load the map the popup window only shows about 2 words before it moves to a new line. How do I get it to automatically resize so that it will appear on 1 line? The training course I am taking does not have this issue, but the instructor is using Folium 0.3.

Here is the code I am using. I am running Python 3.9.7 using VS Code.

import folium
map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles = "Stamen Terrain") 
map.add_child(folium.Marker(location= [38.2,-99.1], popup="Hi this is a marker", icon=folium.Icon(color='green')))
map.save("Map1.html")
1 Answers

You can put the text of the popup inside a folium.Popup() object and specify the max_width parameter to 100%. Extract from the Folium documentation :

max_width (int for pixels or text for percentages, default '100%') – The maximal width of the popup. You can modify your code that way :

map.add_child(
    folium.Marker(
      location= [38.2,-99.1],
      popup=folium.Popup("Hi this is a marker", max_width="100"),
      icon=folium.Icon(color='green')
    )
)
Related