In [1]:
from IPython.display import HTML
import folium
import numpy as np 
from matplotlib import pyplot as plt
import pandas as pd
import vincent

In [2]:
%matplotlib inline

Either creates a chart with matplotlib, save in png and embed in HTML code


In [3]:
x = np.random.randn(100)

f, ax = plt.subplots(figsize=(4,2))
ax.fill_between(np.arange(len(x)), 0, x, where=(x>=0), color='b', interpolate=True)
ax.fill_between(np.arange(len(x)), 0, x, where=(x<0), color='r', interpolate=True)
f.savefig('./figure.png')

textpop = """<div align='center'> <img src='./figure.png' alt='imaginary rainfall anomaly'> </div>"""


Or creates a chart with Vincent: JSON file


In [4]:
data = pd.DataFrame(np.random.randn(100), index=pd.date_range(start='2010-01-01', periods=100), \
                    columns=['rain'])
vis = vincent.Area(data['rain'], width=400, height=200)
vis.axis_titles(x='Date', y='Rain')
vis.to_json('vis.json')

Just so that we can visualize the map into the notebook


In [5]:
def inline_map(map):
    """
    Embeds the HTML source of the map directly into the IPython 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.
    """
    map._build_map()
    return HTML('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 510px; border: none"></iframe>'.format(srcdoc=map.HTML.replace('"', '&quot;')))

def embed_map(map, path="map.html"):
    """
    Embeds a linked iframe to the map into the IPython notebook.
    
    Note: this method will not capture the source of the map into the notebook.
    This method should work for all maps (as long as they use relative urls).
    """
    map.create_map(path=path)
    return HTML('<iframe src="files/{path}" style="width: 100%; height: 510px; border: 3"></iframe>'.format(path=path))

In [6]:
#map = folium.Map(location=[-13.8333, -171.7500], zoom_start=10, tiles='Mapbox', API_key='nicolasf.i7dmljp0')
map = folium.Map(location=[-13.8333, -171.7500], zoom_start=10, tiles='Mapbox', API_key='nicolasf.ic0ebom5')

map.circle_marker(location=[-13.8333, -171.7500], popup=textpop, fill_color='#FF0000', line_color=None, radius=3000)
map.circle_marker(location=[-13.9, -171.7400], popup=textpop, fill_color='#FF0000', line_color=None, radius=2000)

#map.simple_marker([-13.8333, -171.7500], popup=textpop)
#map.simple_marker([-13.8333, -171.7500], popup=(vis,'vis.json'))
inline_map(map)


Out[6]:
"); map.addLayer(circle_1) var circle_2 = L.circle([-13.9, -171.74], 2000, { color: 'None', fillColor: '#FF0000', fillOpacity: 0.6 }); circle_2.bindPopup("
"); map.addLayer(circle_2) " style="width: 100%; height: 510px; border: none">

In [31]:
map.circle_marker?

In [11]:
folium.Map?

In [ ]: