Table of Contents


In [1]:
import pandas as pd
import numpy as np

import sys
# sys.path.insert(0,'..')
import folium
import branca
import crossfolium

In [2]:
N = 100

data = pd.DataFrame(index=range(N))
data['letter'] = list(map(
    lambda x: 'A' if x < 0.2 else 'B' if x<0.6 else 'C',
    np.random.uniform(size=N)
    ))
data['name'] =  list(map(
    lambda x: 'Alpha' if x < 0.2 else 'Beta' if x<0.6 else 'Gamma',
    np.random.uniform(size=N)
    ))
data['lat'] = 35. + 20*np.random.uniform(size=N)
data['lng'] = -10.+ 40*np.random.uniform(size=N)

data['icon'] = data.letter.apply(lambda x: 'question' if x=='A' else 'play' if x=='B' else 'pause')
data['color'] = data.letter.apply(lambda x: 'red' if x=='A' else 'green' if x=='B' else 'blue')

In [6]:
f = branca.element.Figure(height=1000)
c = crossfolium.Crossfilter(
    data.to_dict(orient='records'),
    width='96%',
    left='2%',
    height='96%',
    top='2%',
).add_to(f)

c.add_subplot(2,2,1, margin=0.01).add_child(
    folium.Map([45,10], zoom_start=4, tiles='cartodbpositron').add_child(
        crossfolium.MarkerClusterFilter(
            c,
            name='mkf',
            fit_bounds=False,
            max_cluster_radius=None,
            geofilter=True,
            circle_radius=None,
            color='#0000ff',
            opacity=1.0,
            )))

c.add_subplot(4,4,3, margin=0.01).add_child(crossfolium.PieFilter(
    c,
    'letter',
    name='letter',
    order=['A','B','C'],
    colors=['#ff0000','#00ff00', '#0000ff'],
    ))

c.add_subplot(4,4,4, margin=0.01).add_child(crossfolium.PieFilter(
    c,
    'name',
    name='name',
    order=['Alpha', 'Beta', 'Gamma'],
    colors=['#00ffff','#ff00ff', '#ffff00'],
    ))

c.add_subplot(8,2,6, margin=0.01).add_child(
    crossfolium.BarFilter(
        c,
        'lat', width=400, height=100,
        bar_padding=0.1, domain=[35,55],
        groupby=1,
        elastic_y=True,
        xlabel='',
        ylabel='latitude',
        margins={'top': 10, 'right': 20, 'bottom': 20, 'left': 50},
        xticks=[35,45,55],
        ))

c.add_subplot(8,2,8, margin=0.01).add_child(
    crossfolium.BarFilter(
        c,
        'lng', width=400, height=100,
        bar_padding=0.1, domain=[-10,30],
        groupby=2,
        elastic_y=True,
        xlabel='',
        ylabel='longitude',
        margins={'top': 10, 'right': 20, 'bottom': 20, 'left': 50},
        xticks=[-10,0,10,20,30],
        ))

c.add_subplot(2,1,2, margin=0.01).add_child(
    crossfolium.TableFilter(c, data.columns.values.tolist()
    ))

c


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/xmn/anaconda3/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

/home/xmn/anaconda3/lib/python3.5/site-packages/branca/element.py in _repr_html_(self, **kwargs)
    498             self._parent = None
    499         else:
--> 500             out = self._parent._repr_html_(**kwargs)
    501         return out
    502 

/home/xmn/anaconda3/lib/python3.5/site-packages/branca/element.py in _repr_html_(self, **kwargs)
    309 
    310         """
--> 311         html = self.render(**kwargs)
    312         html = "data:text/html;base64," + base64.b64encode(html.encode('utf8')).decode('utf8')  # noqa
    313 

/home/xmn/anaconda3/lib/python3.5/site-packages/branca/element.py in render(self, **kwargs)
    299         """Renders the HTML representation of the element."""
    300         for name, child in self._children.items():
--> 301             child.render(**kwargs)
    302         return self._template.render(this=self, kwargs=kwargs)
    303 

/home/xmn/anaconda3/lib/python3.5/site-packages/crossfolium/crossfolium.py in render(self, **kwargs)
     58 
     59     def render(self, **kwargs):
---> 60         super(Crossfilter, self).render(**kwargs)
     61 
     62         figure = self._parent.get_root()

/home/xmn/anaconda3/lib/python3.5/site-packages/branca/element.py in render(self, **kwargs)
    468 
    469         for name, element in self._children.items():
--> 470             element.render(**kwargs)
    471 
    472         for name, element in self.header._children.items():

/home/xmn/anaconda3/lib/python3.5/site-packages/branca/element.py in render(self, **kwargs)
    468 
    469         for name, element in self._children.items():
--> 470             element.render(**kwargs)
    471 
    472         for name, element in self.header._children.items():

/home/xmn/anaconda3/lib/python3.5/site-packages/folium/element.py in render(self, **kwargs)
    646         """Renders the HTML representation of the element."""
    647         figure = self.get_root()
--> 648         assert isinstance(figure, Figure), ("You cannot render this Element "
    649                                             "if it's not in a Figure.")
    650 

AssertionError: You cannot render this Element if it's not in a Figure.
Out[6]:
<crossfolium.crossfolium.Crossfilter at 0x7fe9662372b0>

In [ ]: