API reference#

altair_tiles.add_tiles(chart: Chart, provider: Union[str, TileProvider] = 'OpenStreetMap.Mapnik', zoom: Optional[int] = None, attribution: Union[str, bool] = True) LayerChart[source]#

Adds tiles to a chart. The chart must have a geoshape mark and a Mercator projection.

Parameters:
  • chart (alt.Chart) – A chart with a Mercator projection.

  • provider (Union[str, TileProvider], optional) – The provider of the tiles. You can access all available preconfigured providers at altair_tiles.providers such as altair_tiles.providers.OpenStreetMap.Mapnik. For convenience, you can also pass the name as a string, for example “OpenStreetMap.Mapnik” (this is the default). You can pass a custom provider as a TileProvider instance. This functionality is provided by the xyzservices package.

  • zoom (Optional[int], optional) – If None an appropriate zoom level will be calculated automatically, by default None

  • attribution (Union[str, bool], optional) – If True, the default attribution text for the provider, if available, is added to the chart. You can also provide a custom text as a string or disable the attribution text by setting this to False. By default True

Return type:

alt.LayerChart

Raises:
  • TypeError – If chart is not an altair.Chart instance.

  • ValueError – If chart does not have a geoshape mark or a Mercator projection or no projection.

altair_tiles.create_tiles_chart(provider: Union[str, TileProvider] = 'OpenStreetMap.Mapnik', zoom: Optional[int] = None, attribution: Union[str, bool] = True, standalone: Union[bool, Projection] = True) Union[LayerChart, Chart][source]#

Creates an Altair chart with tiles.

Parameters:
  • provider (Union[str, TileProvider], optional) – _description_, by default “OpenStreetMap.Mapnik”

  • provider – The provider of the tiles. You can access all available preconfigured providers at altair_tiles.providers such as altair_tiles.providers.OpenStreetMap.Mapnik. For convenience, you can also pass the name as a string, for example “OpenStreetMap.Mapnik” (this is the default). You can pass a custom provider as a TileProvider instance. This functionality is provided by the xyzservices package.

  • zoom (Optional[int], optional) – If None an appropriate zoom level will be calculated automatically, by default None

  • attribution (Union[str, bool], optional) – If True, the default attribution text for the provider, if available, is added to the chart. You can also provide a custom text as a string or disable the attribution text by setting this to False. By default True

  • standalone (Union[bool, alt.Projection], optional) – If True, the returned chart will have an additional layer with a geoshape mark and a mercator projection set which allows the tiles to properly show up and hence you can render the chart as-is. If False, the chart will be returned in a form where it can be added to an existing chart which must have a projection. You could also add a standalone chart to an existing chart but the resulting specification is slightly simpler if you choose standalone. To customize the projection which is set in the standalone chart, you can also pass an alt.Projection instance here which must have at least type set to mercator, e.g. alt.Projection(type=”mercator”). If you already have a chart, you can pass the projection of the chart, e.g. chart.projection. Defaults to True.

Return type:

Union[alt.LayerChart, alt.Chart]

Raises:

TypeError – If zoom is not an integer or None.

altair_tiles.add_attribution(chart: Union[Chart, LayerChart], provider: Union[str, TileProvider] = 'OpenStreetMap.Mapnik', attribution: Union[bool, str] = True) Union[Chart, LayerChart][source]#

This function is useful if the attribution added by add_tiles or create_tiles_chart would be partially hidden by another layer. In that case, you can set attribution=False when creating the tiles chart and then use this function to add the attribution in the end to the final chart. See the documentation for examples

Parameters:
  • chart (Union[alt.Chart, alt.LayerChart]) – A chart to which you want to have the attribution added.

  • provider (Union[str, TileProvider], optional) – The provider of the tiles. You can access all available preconfigured providers at altair_tiles.providers such as altair_tiles.providers.OpenStreetMap.Mapnik. For convenience, you can also pass the name as a string, for example “OpenStreetMap.Mapnik” (this is the default). You can pass a custom provider as a TileProvider instance. This functionality is provided by the xyzservices package.

  • attribution (Union[str, bool], optional) – If True, the default attribution text for the provider, if available, is added to the chart. You can also provide a custom text as a string or disable the attribution text by setting this to False. By default True

Return type:

Union[alt.Chart, alt.LayerChart]

Providers#

Preconfigured tile providers are provided by the xyzservices package. The xyzservices.providers module is accessible as altair_tiles.providers. See A full look into providers objects - xyzservices for the documentation.

You can also access xyzservices.TileProvider at altair_tiles.TileProvider to configure a custom tile provider. See API reference - xyzservices for the documentation.