https://github.com/mapbox/mapboxgl-jupyter
Property | Description | Example |
---|---|---|
scale | controls visibility of map scale annotation | True |
scale_position | controls the position of the map scale in the map controls pane | 'bottom-right' |
scale_background_color | string background color for scale | 'white' |
scale_border_color | string border color for scale | 'white' |
scale_text_color | string color for legend text | '#6e6e6e' |
scale=True,
scale_border_color='#eee',
scale_background_color='red',
import pandas as pd
import os
from mapboxgl.utils import *
from mapboxgl.viz import *
# Set Mapbox Acces Token; Must be a public token, starting with `pk`
token = os.getenv('MAPBOX_ACCESS_TOKEN')
# Load data from sample csv
data_url = 'https://raw.githubusercontent.com/mapbox/mapboxgl-jupyter/master/examples/data/points.csv'
df = pd.read_csv(data_url).round(3)
# Generate data breaks using numpy quantiles and color stops from colorBrewer
measure = 'Avg Medicare Payments'
color_breaks = [round(df[measure].quantile(q=x*0.1), 2) for x in range(1,9)]
color_stops = create_color_stops(color_breaks, colors='YlOrRd')
# Create a geojson Feature Collection from the current dataframe
geodata = df_to_geojson(df,
properties=['Avg Medicare Payments', 'Avg Covered Charges', 'date'],
lat='lat',
lon='lon',
precision=3)
# Create the viz from the dataframe
viz = CircleViz(geodata,
access_token=token,
color_property='Avg Medicare Payments',
color_stops=color_stops,
radius=2.5,
stroke_width=0.2,
center=(-95, 40),
zoom=2.5,
scale=True,
scale_unit_system='imperial',
below_layer='waterway-label',
height='300px')
# Show the viz
viz.show()
# Map settings
viz.style='mapbox://styles/mapbox/dark-v9?optimize=true'
viz.label_color = 'hsl(0, 0%, 70%)'
viz.label_halo_color = 'hsla(0, 0%, 10%, 0.75)'
viz.height = '400px'
# Legend settings
viz.legend_gradient = False
viz.legend_fill = '#343332'
viz.legend_header_fill = '#343332'
viz.legend_text_color = 'hsl(0, 0%, 70%)'
viz.legend_key_borders_on = False
viz.legend_title_halo_color = 'hsla(0, 0%, 10%, 0.75)'
# Scale settings
viz.scale_border_color = 'hsla(0, 0%, 10%, 0.75)'
viz.scale_position = 'top-left'
viz.scale_background_color = '#343332'
viz.scale_text_color = 'hsl(0, 0%, 70%)'
# Render map
viz.show()