python-visualization / folium

Python Data. Leaflet.js Maps.
https://python-visualization.github.io/folium/
MIT License
6.93k stars 2.23k forks source link

Fit bounds not fitting to provided points #1877

Open this-josh opened 9 months ago

this-josh commented 9 months ago

Describe the bug I have a plot which I'd like to export as png so I'm using the _to_png feature. Ideally I'd like a zoom level of around 4.5 - my plot should cover from Madrid to St.Petersburg (roughly) - but I cannot provide this. When I provide bounds the image I get out doesn't seem to be obeying them.

I appreciate this is likely a function of dynamic window resizing, but exporting as png should be able to adhere to the provided bounds despite the png support being via selenium.

To Reproduce

import folium

m = folium.Map()

sw = [38, -3]
ne = [60, 31]
m.fit_bounds([sw, ne]) 

m.save("map.html")

import io
from PIL import Image

img_data = m._to_png(1)
img = Image.open(io.BytesIO(img_data))
img.save('map_plot.png')

Expected behavior A png file contained within the provided bounds

Environment (please complete the following information):