#!/usr/bin/env python # coding: utf-8 # In[1]: import os import folium print(folium.__version__) # In[2]: from branca.element import Figure lon, lat = -122.1889, 46.1991 location = [lat, lon] zoom_start = 13 tiles = 'OpenStreetMap' # # Using same width and height triggers the scroll bar # In[3]: width, height = 480, 350 fig = Figure(width=width, height=height) m = folium.Map( location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start ) fig.add_child(m) fig.save(os.path.join('results', 'WidthHeight_0.html')) fig # # Can figure take relative sizes? # In[4]: width, height = '100%', 350 fig = Figure(width=width, height=height) m = folium.Map( location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start ) fig.add_child(m) fig.save(os.path.join('results', 'WidthHeight_1.html')) fig # # I guess not. (Well, it does make sense for a single HTML page, but not for iframes.) # In[5]: width, height = 480, '100%' fig = Figure(width=width, height=height) m = folium.Map( location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start ) fig.add_child(m) fig.save(os.path.join('results', 'WidthHeight_2.html')) fig # # Not that Figure is interpreting this as 50px. We should raise something and be explicit on the docs. # In[6]: width, height = '50%', '100%' fig = Figure(width=width, height=height) m = folium.Map( location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start ) fig.add_child(m) fig.save(os.path.join('results', 'WidthHeight_3.html')) fig # In[7]: width, height = '150%', '100%' try: folium.Map(location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start) except ValueError as e: print(e) # In[8]: width, height = '50%', '80p' try: folium.Map(location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start) except ValueError as e: print(e) # In[9]: width, height = width, height = 480, -350 try: folium.Map(location=location, tiles=tiles, width=width, height=height, zoom_start=zoom_start) except ValueError as e: print(e) # # Maybe we should recommend # In[10]: width, height = 480, 350 fig = Figure(width=width, height=height) m = folium.Map( location=location, tiles=tiles, width='100%', height='100%', zoom_start=zoom_start ) fig.add_child(m) fig.save(os.path.join('results', 'WidthHeight_4.html')) fig