Introduction#

This package is in an early development stage. Use it with care and you should expect things to break unannounced until we release a version 1.0.0.

You can use altair_tiles to add tiles from any xyz tile provider such as OpenStreetMap to your Altair chart. It is a counterpart to the amazing contextily package which provides this functionality for matplotlib.

For a general introduction to plotting geographic data with Altair, see Geoshape - Vega-Altair and Specifying Data - Vega-Altair.

Installation#

pip install altair_tiles
# or
conda install -c conda-forge altair_tiles

Basic example#

import altair as alt
import altair_tiles as til
import geopandas as gpd
gdf_ne = gpd.read_file("https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip")  # zipped shapefile
extent_roi = gdf_ne.loc[gdf_ne["CONTINENT"] == "Africa", ["CONTINENT", "geometry"]]

chart = (
    alt.Chart(extent_roi)
    .mark_geoshape(fillOpacity=0.1, stroke="green", strokeWidth=2)
    .project(type="mercator")
)
til.add_tiles(chart).properties(width=600, height=400)