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', marker_color='green')
m.show()
Marker(37.78, -122.42, 'San Francisco').format(marker_icon='thumbs-up').show()
m


Out[5]:

In [6]:
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[6]:

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


Out[7]:

In [8]:
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'], marker_color='black')


Out[8]:

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


Out[9]:

In [10]:
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[10]:

Regions


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


Out[11]:

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


Out[12]:

Binding Data


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


Out[13]:
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 [14]:
states.color(unemployment)


Out[14]:

Maps in tables


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


State Region
AL
AK
AZ

... (47 rows omitted)