简体   繁体   中英

Export a folium map as a png

I'm working with a map created using python, folium, and geojson, similar to this one .

However, instead of this image being an interactive HTML document, I would rather simply export it to png or svg.

Using the syntax:

m = folium.Map( # etc..)
m.save("filename.png")

Saves a file, but it is still HTML, rather than png. What's the correct output command to render not-to-html?

I use this:

... where m is my map object. And 5 is the time (seconds) to render the map.

import io
from PIL import Image

img_data = m._to_png(5)
img = Image.open(io.BytesIO(img_data))
img.save('image.png')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM