Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 765
Mittenchops Avatar asked Nov 30 '18 22:11

Mittenchops


1 Answers

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')
like image 184
Michel Metran Avatar answered Oct 05 '22 10:10

Michel Metran