In [1]:
%matplotlib inline
import pandas as pd
import folium
from matplotlib.colors import Normalize, rgb2hex
import matplotlib.cm as cm

In [2]:
data = pd.read_csv('http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.csv')
norm = Normalize(data['mag'].min(), data['mag'].max())

map = folium.Map(location=[48, -102], zoom_start=3)
for eq in data.iterrows():
    color = rgb2hex(cm.OrRd(norm(float(eq[1]['mag']))))
    map.circle_marker([eq[1]['latitude'], eq[1]['longitude']], 
                    popup=eq[1]['place'], 
                    radius=20000*float(eq[1]['mag']),
                    line_color=color,
                    fill_color=color)
map.create_map(path='/home/hermantolentino/notebook.epispider.io/public_html/earthquake.html')
# need to replace CDN with https URLs
with open('/home/hermantolentino/notebook.epispider.io/public_html/earthquake.html', 'r') as f:
    contents = f.read()
    contents = contents.replace("http://cdn.leafletjs.com/leaflet-0.5/", "//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/")
    with open('/home/hermantolentino/notebook.epispider.io/public_html/earthquake2.html', 'w') as f:
        f.writelines(contents)


/venv35/lib/python3.4/site-packages/ipykernel/__main__.py:11: FutureWarning: circle_marker is deprecated. Use add_children(CircleMarker) instead
/venv35/lib/python3.4/site-packages/ipykernel/__main__.py:12: FutureWarning: Map.create_map is deprecated. Use Map.save instead
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-1c335abdcbd1> in <module>()
     10                     line_color=color,
     11                     fill_color=color)
---> 12 map.create_map(path='/home/hermantolentino/notebook.epispider.io/public_html/earthquake.html')
     13 # need to replace CDN with https URLs
     14 with open('/home/hermantolentino/notebook.epispider.io/public_html/earthquake.html', 'r') as f:

/venv35/lib/python3.4/site-packages/folium/folium.py in create_map(self, path, plugin_data_out, template)
    125                                                             "Map.save"),
    126                       FutureWarning, stacklevel=2)
--> 127         self.save(path)
    128 
    129     def add_wms_layer(self, wms_name=None, wms_url=None, wms_format=None,

/venv35/lib/python3.4/site-packages/folium/element.py in save(self, outfile, close_file, **kwargs)
    146         """
    147         if isinstance(outfile, text_type) or isinstance(outfile, binary_type):
--> 148             fid = open(outfile, 'wb')
    149         else:
    150             fid = outfile

FileNotFoundError: [Errno 2] No such file or directory: '/home/hermantolentino/notebook.epispider.io/public_html/earthquake.html'

In [ ]:
%%HTML
<iframe width="100%" height="450" src="https://notebook.epispider.io/earthquake2.html?inline=true"></iframe>