https://github.com/mapbox/mapboxgl-jupyter
import random
import os
from mapboxgl.viz import LinestringViz
from mapboxgl.utils import create_color_stops, create_numeric_stops
# Must be a public token, starting with `pk`
token = os.getenv('MAPBOX_ACCESS_TOKEN')
# JSON join-data object
data = [{"elevation": x, "weight": random.randint(0,100)} for x in range(0, 21000, 10)]
# GeoJSON data object
geojson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"id": "01",
"properties": {"sample": 50, "weight": 1},
"geometry": {
"type": "LineString",
"coordinates": [
[-122.4833858013153, 37.829607404976734],
[-122.4830961227417, 37.82932776098012],
[-122.4830746650696, 37.82932776098012],
[-122.48218417167662, 37.82889558180985],
[-122.48218417167662, 37.82890193740421],
[-122.48221099376678, 37.82868372835086],
[-122.4822163581848, 37.82868372835086],
[-122.48205006122589, 37.82801003030873]
]
}
}, {
"type": "Feature",
"id": "02",
"properties": {"sample": 500, "weight": 2},
"geometry": {
"type": "LineString",
"coordinates": [
[-122.4833858013153, 37.929607404976734],
[-122.4830961227417, 37.83]
]
}
}, {
"type": "Feature",
"properties": {"sample": 5000, "weight": 1},
"geometry": {
"type": "LineString",
"coordinates": [
[-122.48369693756104, 37.83381888486939],
[-122.48348236083984, 37.83317489144141],
[-122.48339653015138, 37.83270036637107],
[-122.48356819152832, 37.832056363179625],
[-122.48404026031496, 37.83114119107971],
[-122.48404026031496, 37.83049717427869],
[-122.48348236083984, 37.829920943955045],
[-122.48356819152832, 37.82954808664175],
[-122.48507022857666, 37.82944639795659],
[-122.48610019683838, 37.82880236636284],
[-122.48695850372314, 37.82931081282506],
[-122.48700141906738, 37.83080223556934],
[-122.48751640319824, 37.83168351665737],
[-122.48803138732912, 37.832158048267786],
[-122.48888969421387, 37.83297152392784],
[-122.48987674713133, 37.83263257682617],
[-122.49043464660643, 37.832937629287755],
[-122.49125003814696, 37.832429207817725],
[-122.49163627624512, 37.832564787218985],
[-122.49223709106445, 37.83337825839438],
[-122.49378204345702, 37.83368330777276]
]
}
}]
}
# make viz with GeoJSON source
viz = LinestringViz(geojson,
access_token=token,
color_property='sample',
color_stops=create_color_stops([0, 50, 100, 500, 1500], colors='Blues'),
line_stroke='--',
line_width_property='weight',
line_width_stops=create_numeric_stops([0, 1, 2, 3, 4, 5], 0, 10),
opacity=0.8,
center=(-122.48, 37.83),
zoom=12,
below_layer='waterway-label')
viz.show()
viz = LinestringViz(data,
access_token=token,
vector_url='mapbox://mapbox.mapbox-terrain-v2',
vector_layer_name='contour',
vector_join_property='ele',
data_join_property='elevation',
color_property='elevation',
color_stops=create_color_stops([0, 50, 100, 200, 300], colors='YlOrRd'),
line_width_stops=create_numeric_stops([0, 50, 100, 200, 300], 0.1, 4),
line_width_property='elevation',
line_width_function_type='interpolate',
line_width_default='1',
opacity=0.8,
center=(-122.48, 37.83),
zoom=13,
below_layer='waterway-label')
viz.show()