In [1]:
import os
import folium

print(folium.__version__)


0.5.0+27.g2d457b0.dirty

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


Out[3]:

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


Out[4]:

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


Out[5]:

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


Out[6]:

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)


Cannot parse value 150.0 as '%'

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)


Cannot parse value '80p' as '%'

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)


Cannot parse value -350.0 as 'px'

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


Out[10]: