'Adjust the size of folium popups
Site_Number | Site_Description | Region_Site | Latitude | Longitude | S1_AverageSpeed | S1_85thSpeed | S2_AverageSpeed | S2_85thSpeed | S3_AverageSpeed | S3_85thSpeed | String_for_Popup |
---|---|---|---|---|---|---|---|---|---|---|---|
1.0 | A6093 | Pencaitland, A6093 (Site 1) | 55.91 | -2.89 | 25.15 | 30.07 | 25.78 | 30.55 | NaN | NaN | Site Number: 1.0 Description: A6093 S1 Average Speed: 25.15 S1 85th %ile Speed: 30.07 S2 Average Speed: 25.78 S2 85th %ile Speed: 30.55 S3 Average Speed: nan S3 85th %ile Speed: nan ' |
2.0 | B1345 Main Road | Dirleton, B1345 Main Road (Site 2) | 56.05 | -2.78 | 23.14 | 28.23 | 23.0 | 28.54 | 22.04 | 26.72 | Site Number: 2.0 Description: B1345 Main Road S1 Average Speed: 23.14 S1 85th %ile Speed: 28.23 S2 Average Speed: 23.0 S2 85th %ile Speed: 28.54 S3 Average Speed: 22.04 S3 85th %ile Speed: 26.72 |
3.0 | Main Road | Macmerry, Main Road (Site 3) | 55.94 | -2.91 | 29.72 | 34.05 | 26.88 | 32.4 | NaN | NaN | Site Number: 3.0 Description: Main Road S1 Average Speed: 29.72 S1 85th %ile Speed: 34.05 S2 Average Speed: 26.88 S2 85th %ile Speed: 32.4 S3 Average Speed: nan S3 85th %ile Speed: nan |
I am working with a table like the one above, and I have written code to plot each set of latitudes and longitudes with the popup set to equal the popup string which contains pre-formatted HTML strings.
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():
folium.Marker([location_info["Latitude"], location_info["Longitude"]], popup=location_info["String_for_Popup"], tooltip=location_info["Site_Description"]).add_to(map)
This does manage to plot all the points with the correct popup, however the size of the popup message is too narrow and so splits the string over multiple lines as seen in the picture below:
Is there a way to adjust the width of the popups so that each value can fit on its own line?
Solution 1:[1]
Here is example that worked for me:
fgroup.add_child(folium.Marker(location=[39.28173017251679, -74.5628182419811],
popup=folium.Popup("Golfing, Jetskiing and surfing", max_width=300,min_width=300),
icon=folium.Icon(color='red')))
Solution 2:[2]
I added the following, I hope this example helps you
folium.Marker(
location=[lat, long],
popup=folium.Popup(f"<h5>{rec_type}</h5>{caption}", max_width=300,min_width=300),
icon=folium.Icon(color=test, icon=icon,prefix=prefix)).add_to(m)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Muhteva |
Solution 2 | Sif Baksh |