Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Embed folium maps in iPython
def embed(fmaps, width='100%', height='510px', *args, **kwargs):
"""
Embeds a folium map in a IPython/Jupyter notebook.
This method will not work if the map depends on any files (json data). Also this uses
the HTML5 srcdoc attribute, which may not be supported in all browsers.
fmaps -- a single folium map or an iterable containing folium maps
"""
from IPython.display import HTML
template = '<iframe srcdoc="{srcdoc}" style="width: {width}; height: {height}; border: none"></iframe>'
html = ''
try:
for fmap in fmaps:
fmap._build_map()
html += template.format(
srcdoc=fmap.HTML.replace('"', '&quot;'),
height=str(height),
width=str(width),
)
except TypeError:
fmap = fmaps
fmap._build_map()
html = template.format(
srcdoc=fmap.HTML.replace('"', '&quot;'),
height=str(height),
width=str(width),
)
return HTML(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.