Maps (datascience.maps)

Draw maps using folium.

class datascience.maps.Map(features=(), ids=(), width=960, height=500, **kwargs)[source]

A map from IDs to features. Keyword args are forwarded to folium.

color(values, ids=(), key_on='feature.id', palette='YlOrBr', **kwargs)[source]

Color map features by binning values.

values – a sequence of values or a table of keys and values ids – an ID for each value; if none are provided, indices are used key_on – attribute of each feature to match to ids palette – one of the following color brewer palettes:

‘BuGn’, ‘BuPu’, ‘GnBu’, ‘OrRd’, ‘PuBu’, ‘PuBuGn’, ‘PuRd’, ‘RdPu’, ‘YlGn’, ‘YlGnBu’, ‘YlOrBr’, and ‘YlOrRd’.

Defaults from Folium:

threshold_scale: list, default None
Data range for D3 threshold scale. Defaults to the following range of quantiles: [0, 0.5, 0.75, 0.85, 0.9], rounded to the nearest order-of-magnitude integer. Ex: 270 rounds to 200, 5600 to 6000.
fill_opacity: float, default 0.6
Area fill opacity, range 0-1.
line_color: string, default ‘black’
GeoJSON geopath line color.
line_weight: int, default 1
GeoJSON geopath line weight.
line_opacity: float, default 1
GeoJSON geopath line opacity, range 0-1.
legend_name: string, default None
Title for data legend. If not passed, defaults to columns[1].
features
format(**kwargs)[source]

Apply formatting.

geojson()[source]

Render features as a FeatureCollection.

classmethod read_geojson(path_or_json_or_string)[source]

Read a geoJSON string, object, or file. Return a dict of features keyed by ID.

class datascience.maps.Marker(lat, lon, popup='', color='blue', **kwargs)[source]

A marker displayed with Folium’s simple_marker method.

popup – text that pops up when marker is clicked color – fill color

Defaults from Folium:

marker_icon: string, default ‘info-sign’
icon from (http://getbootstrap.com/components/) you want on the marker
clustered_marker: boolean, default False
boolean of whether or not you want the marker clustered with other markers
icon_angle: int, default 0
angle of icon
popup_width: int, default 300
width of popup
copy()[source]

Return a deep copy

format(**kwargs)[source]

Apply formatting.

geojson(feature_id)[source]

GeoJSON representation of the marker as a point.

lat_lons
classmethod map(latitudes, longitudes, labels=None, colors=None, radii=None, **kwargs)[source]

Return markers from columns of coordinates, labels, & colors.

The radii column is not applicable to markers, but sets circle radius.

classmethod map_table(table, **kwargs)[source]

Return markers from the colums of a table.

class datascience.maps.Circle(lat, lon, popup='', color='blue', radius=10, **kwargs)[source]

A marker displayed with Folium’s circle_marker method.

popup – text that pops up when marker is clicked color – fill color radius – pixel radius of the circle

Defaults from Folium:

fill_opacity: float, default 0.6
Circle fill opacity

For example, to draw three circles:

t = Table().with_columns([
‘lat’, [37.8, 38, 37.9], ‘lon’, [-122, -122.1, -121.9], ‘label’, [‘one’, ‘two’, ‘three’], ‘color’, [‘red’, ‘green’, ‘blue’], ‘radius’, [3000, 4000, 5000],

])

Circle.map_table(t)

class datascience.maps.Region(geojson, **kwargs)[source]

A GeoJSON feature displayed with Folium’s geo_json method.

copy()[source]

Return a deep copy

format(**kwargs)[source]

Apply formatting.

geojson(feature_id)[source]

Return GeoJSON with ID substituted.

lat_lons

A flat list of (lat, lon) pairs.

polygons

Return a list of polygons describing the region.

  • Each polygon is a list of linear rings, where the first describes the exterior and the rest describe interior holes.
  • Each linear ring is a list of positions where the last is a repeat of the first.
  • Each position is a (lat, lon) pair.
properties
type

The GEOJSON type of the regions: Polygon or MultiPolygon.