In [1]:
from datascience import *

Basic Map


In [2]:
Map()


Out[2]:

In [3]:
Map(zoom_start=16)


Out[3]:

Markers


In [4]:
Marker(37.78, -122.42, 'San Francisco')


Out[4]:

In [5]:
m = Marker(37.78, -122.42, 'San Francisco', color='green')
m.show()
Marker(37.78, -122.42, 'San Francisco').format(marker_icon='thumbs-up').show()
m


Out[5]:

In [6]:
# Test different tile styles
Map(tiles='Stamen Toner').show()
Map(tiles='Stamen Terrain')


Out[6]:

In [7]:
features = [
    Marker(51.5135015, -0.1358392, 'A'), 
    Marker(51.5137, -0.1358392, 'B'), 
    Marker(51.5132, -0.138, 'C'), 
    Marker(51.5143, -0.135, 'D')
]
Map(features)


Out[7]:

In [8]:
Map(features, zoom_start=15)


Out[8]:

In [9]:
points = [
    (51.5135015, -0.1358392), 
    (51.5137, -0.1358392), 
    (51.5132, -0.138), 
    (51.5143, -0.135),
]
lats, lons = zip(*points)
Marker.map(lats, lons, ['A', 'B', 'C', 'D'], color='black')


/Users/ahemani/Development/data8/datascience/datascience/maps.py:458: UserWarning: color argument of Icon should be one of: {'darkgreen', 'darkpurple', 'lightgreen', 'darkred', 'cadetblue', 'lightblue', 'orange', 'blue', 'lightred', 'white', 'beige', 'darkblue', 'gray', 'pink', 'red', 'purple', 'green', 'lightgrayblack'}.
  attrs['icon'] = folium.Icon(**icon_args)
Out[9]:

In [10]:
colors = ['red', 'blue', 'gray', 'green']
icons = ['thumbs-up', 'info-sign', 'thumbs-up', 'info-sign']
t = Table().with_columns(*zip(['lat', 'lon', 'labels', 'color', 'marker_icon'], [lats, lons, colors, colors, icons]))
t.show()
Marker.map_table(t)


lat lon labels color marker_icon
51.5135 -0.135839 red red thumbs-up
51.5137 -0.135839 blue blue info-sign
51.5132 -0.138 gray gray thumbs-up
51.5143 -0.135 green green info-sign
Out[10]:

In [11]:
colors = ['red', 'blue', 'yellow', 'green']
Circle.map(lats, lons, colors=colors, fill_opacity=0.8, radius=20)


Out[11]:

In [12]:
names = colors
t = Table().with_columns(*zip(['lat', 'lon', 'name', 'color'], [lats, lons, names, colors]))
t.show()
Circle.map_table(t, radius=20)


lat lon name color
51.5135 -0.135839 red red
51.5137 -0.135839 blue blue
51.5132 -0.138 yellow yellow
51.5143 -0.135 green green
Out[12]:

Regions


In [13]:
states = Map.read_geojson('us-states.json')
states


Out[13]:

In [14]:
Map([states['CA'], states['NV'].format(color='yellow')])


Out[14]:

In [15]:
# Reading in GeoJSON from link
url = "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json"
Map.read_geojson(url)


Out[15]:

Binding Data


In [16]:
from datascience import *

In [17]:
unemployment = Table.read_table('us-unemployment.csv')
unemployment


Out[17]:
State Unemployment
AL 7.1
AK 6.8
AZ 8.1
AR 7.2
CA 10.1
CO 7.7
CT 8.4
DE 7.1
FL 8.2
GA 8.8

... (40 rows omitted)


In [18]:
states.color(unemployment)


Out[18]:

Maps in tables


In [19]:
Table().with_columns(
    'State', states.keys(),
    'Region', states.values()).show(3)


State Region
AL
AK
AZ

... (47 rows omitted)


In [ ]: