https://github.com/mapbox/mapboxgl-jupyter
These examples require the installation of the following python modules
pip install mapboxgl
ImageViz
object accepts either an url, a local path or a numpy ndarray data as input for an image source
import os
import numpy
from matplotlib.pyplot import imread
from mapboxgl.viz import ImageViz
Set a MAPBOX_ACCESS_TOKEN
environment variable or copy/paste your token
If you do not have a Mapbox access token, sign up for an account at https://www.mapbox.com/
If you already have an account, you can grab your token at https://www.mapbox.com/account/
# Must be a public token, starting with `pk`
token = os.getenv('MAPBOX_ACCESS_TOKEN')
img_url = 'https://raw.githubusercontent.com/mapbox/mapboxgl-jupyter/master/examples/data/mosaic.png'
# Coordinates must be an array in the form of [UL, UR, LR, LL]
coordinates = [[-123.40515640309, 38.534294809274336],
[-115.92938988349292, 38.534294809274336],
[-115.92938988349292, 32.08296982365502],
[-123.40515640309, 32.08296982365502]]
# Create the viz from the dataframe
viz = ImageViz(img_url,
coordinates,
access_token=token,
height='600px',
center=(-119, 35),
zoom=5,
below_layer='waterway-label')
viz.show()
img = imread(img_url)
img = numpy.mean(img[::10, ::10], axis=2)
# Coordinates must be an array in the form of [UL, UR, LR, LL]
coordinates = [[-123.40515640309, 38.534294809274336],
[-115.92938988349292, 38.534294809274336],
[-115.92938988349292, 32.08296982365502],
[-123.40515640309, 32.08296982365502]]
# Create the viz from the dataframe
viz = ImageViz(img,
coordinates,
access_token=token,
height='600px',
center=(-119, 35),
zoom=5,
below_layer='waterway-label')
viz.show()
# Coordinates must be an array in the form of [UL, UR, LR, LL]
coordinates = [[-123.40515640309, 38.534294809274336],
[-115.92938988349292, 38.534294809274336],
[-115.92938988349292, 32.08296982365502],
[-123.40515640309, 32.08296982365502]]
# Create the viz from the dataframe
viz = ImageViz(img_url,
coordinates,
access_token=token,
height='600px',
center=(-119, 35),
zoom=5,
below_layer='waterway-label')
viz.show()
from matplotlib import cm
img = imread(img_url)
img = numpy.mean(img[::10, ::10], axis=2)
img = cm.magma(img)
# Coordinates must be an array in the form of [UL, UR, LR, LL]
coordinates = [[-123.40515640309, 38.534294809274336],
[-115.92938988349292, 38.534294809274336],
[-115.92938988349292, 32.08296982365502],
[-123.40515640309, 32.08296982365502]]
# Create the viz from the dataframe
viz = ImageViz(img_url,
coordinates,
access_token=token,
height='600px',
center=(-119, 35),
zoom=5,
below_layer='waterway-label')
viz.show()