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
¶
-
overlay
(feature, color='Blue', opacity=0.6)[source]¶ Overlays
feature
on the map. Returns a new Map.- Args:
feature
: aTable
of map features, a list of map features,- a Map, a Region, or a circle marker map table. The features will
be overlayed on the Map with specified
color
.
color
(str
): Color of feature. Defaults to ‘Blue’opacity
(float
): Opacity of overlain feature. Defaults to- 0.6.
- Returns:
- A new
Map
with the overlainfeature
.
-
-
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
-
lat_lons
¶
-
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.
-
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.
-