In [1]:
# This is to import the repository's version of folium ; not the installed one.
import sys, os
sys.path.insert(0,'..')

In [2]:
import branca
import folium
from folium import features

In [3]:
import numpy as np

ColorLine


In [4]:
lats = 20 * np.cos(np.linspace(0, 2*np.pi, 300))
lons = 20 * np.sin(np.linspace(0, 2*np.pi, 300))
colors = np.sin(5 * np.linspace(0, 2*np.pi, 300))

In [5]:
m = folium.Map([0, 0], zoom_start=3)
color_line = features.ColorLine(
    list(zip(lats, lons)),
    colors=colors,
    colormap=['y', 'orange', 'r'],
    weight=10)
color_line.add_to(m)
m


Out[5]:

WMS


In [6]:
m = folium.Map([40,-100], zoom_start=4)
w = features.WmsTileLayer("http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi",
        name='test',
        format='image/png',
        layers='nexrad-n0r-900913',
        attr=u"Weather data © 2012 IEM Nexrad",
        transparent=True)
w.add_to(m)
m


Out[6]:

Marker, Icon, Popup


In [7]:
f = branca.element.Figure(figsize=(8,8))
m = folium.Map([0,0], zoom_start=1)
mk = features.Marker([0,0])
pp = features.Popup("hello")
ic = features.Icon(color='red')

f.add_children(m)
mk.add_children(ic)
mk.add_children(pp)
m.add_children(mk)

f


Out[7]:

RegularPolygonMarker


In [8]:
f = branca.element.Figure()
m = folium.Map([0,0], zoom_start=1)
mk = features.RegularPolygonMarker([0,0])
mk2 = features.RegularPolygonMarker([0,45])

f.add_children(m)
m.add_children(mk)
m.add_children(mk2)

f


Out[8]:

Vega stuff


In [9]:
import vincent, json
import numpy as np
N=100
multi_iter2 = {'x' : np.random.uniform(size=(N,)),
               'y' : np.random.uniform(size=(N,)),
               }
scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=100, width=200)
data = json.loads(scatter.to_json())

f = branca.element.Figure()
m = folium.Map([0,0], zoom_start=1)
mk = features.Marker([0,0])
p = features.Popup("Hello")
v = features.Vega(data, width="100%", height="100%")
f.add_children(m)
mk.add_children(p)
p.add_children(v)
m.add_children(mk)

f


Out[9]:

Vega div


In [10]:
import vincent, json
import numpy as np
N=100
multi_iter2 = {'x' : np.random.uniform(size=(N,)),
               'y' : np.random.uniform(size=(N,)),
               }
scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=400, width=600)
data = json.loads(scatter.to_json())

f = branca.element.Figure()
v = features.Vega(data, height=40, width=600)
f.add_children(v)

f


Out[10]:

A div and a Map


In [11]:
import vincent, json
import numpy as np
N=100
multi_iter2 = {'x' : np.random.uniform(size=(N,)),
               'y' : np.random.uniform(size=(N,)),
               }
scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=250, width=420)
data = json.loads(scatter.to_json())

f = branca.element.Figure()

# Create two maps
m = folium.Map([0,0], tiles='stamenwatercolor',
                 zoom_start=1, position='absolute', left="0%", width="50%", height="50%")
m2 = folium.Map([46,3], tiles='mapquestopen',
                  zoom_start=4, position='absolute', left="50%", width="50%", height='50%',top='50%')

# Create two Vega
v = features.Vega(data, position='absolute', left="50%", width="50%", height="50%")

v2 = features.Vega(data, position='absolute', left="0%", width="50%", height="50%", top='50%')

f.add_children(m)
f.add_children(m2)
f.add_children(v)
f.add_children(v2)

f


Out[11]:

GeoJson


In [12]:
N=1000
lons = +5 - np.random.normal(size=N)
lats = 48 - np.random.normal(size=N)

data = {
    "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "MultiPoint",
                    "coordinates": [[lon, lat] for (lat,lon) in zip(lats,lons)],
                    },
                "properties": {"prop0": "value0"}
                },
        ],
    }
m = folium.Map([48.,5.], zoom_start=6)
m.add_children(features.GeoJson(data))
m


Out[12]:

Marker Cluster


In [13]:
N = 100
data = np.array([
    np.random.uniform(low=35,high=60, size=N),   # random latitudes in Europe
    np.random.uniform(low=-12,high=30, size=N),  # random longitudes in Europe
    range(N),                                    # popups are simple numbers 
    ]).T
m = folium.Map([45.,3.], zoom_start=4)
mc = features.MarkerCluster()

for i in range(N):
    mk = features.Marker([data[i][0],data[i][1]])
    p = features.Popup(str(data[i][2]))
    mk.add_children(p)
    mc.add_children(mk)

m.add_children(mc)
m


Out[13]:

Div


In [14]:
import vincent, json
import numpy as np
N=100
multi_iter2 = {'x' : np.random.uniform(size=(N,)),
               'y' : np.random.uniform(size=(N,)),
               }
scatter = vincent.Scatter(multi_iter2, iter_idx='x', height=250, width=420)
data = json.loads(scatter.to_json())

f = branca.element.Figure()

d1 = f.add_subplot(1,2,1)
d2 = f.add_subplot(1,2,2)

d1.add_children(folium.Map([0,0], tiles='stamenwatercolor', zoom_start=1))
d2.add_children(folium.Map([46,3], tiles='mapquestopen', zoom_start=5))

f


Out[14]:

LayerControl


In [15]:
m = folium.Map(tiles=None)

folium.TileLayer('mapquestopen').add_to(m)
folium.TileLayer('stamentoner').add_to(m)

folium.LayerControl().add_to(m)
m


Out[15]:

ScrollZoomToggler


In [16]:
import folium.plugins

In [17]:
m = folium.Map()

folium.plugins.ScrollZoomToggler().add_to(m)

m


Out[17]:

Terminator


In [18]:
m = folium.Map()

folium.plugins.Terminator().add_to(m)

m


Out[18]: