{ "cells": [ { "cell_type": "markdown", "id": "c554e753", "metadata": {}, "source": [ "# Interactive mapping\n", "\n", "Alongside static plots, `geopandas` can create interactive maps based on the [folium](https://python-visualization.github.io/folium/) library.\n", "\n", "Creating maps for interactive exploration mirrors the API of static [plots](../reference/api/geopandas.GeoDataFrame.plot.html) in an [explore()](../reference/api/geopandas.GeoDataFrame.explore.html) method of a GeoSeries or GeoDataFrame.\n", "\n", "Loading some example data:" ] }, { "cell_type": "code", "execution_count": null, "id": "caf2fbd5", "metadata": {}, "outputs": [], "source": [ "import geopandas\n", "import geodatasets\n", "\n", "nybb = geopandas.read_file(geodatasets.get_path(\"nybb\"))\n", "chicago = geopandas.read_file(geodatasets.get_path(\"geoda.chicago_commpop\"))\n", "groceries = geopandas.read_file(geodatasets.get_path(\"geoda.groceries\")).explode(ignore_index=True)" ] }, { "cell_type": "markdown", "id": "56bf1bcf", "metadata": {}, "source": [ "The simplest option is to use `GeoDataFrame.explore()`:" ] }, { "cell_type": "code", "execution_count": null, "id": "6b484ecc", "metadata": {}, "outputs": [], "source": [ "nybb.explore()" ] }, { "cell_type": "markdown", "id": "7a797389", "metadata": {}, "source": [ "Interactive plotting offers largely the same customisation as static one plus some features on top of that. Check the code below which plots a customised choropleth map. You can use `\"BoroName\"` column with NY boroughs names as an input of the choropleth, show (only) its name in the tooltip on hover but show all values on click. You can also pass custom background tiles (either a name supported by folium, a name recognized by `xyzservices.providers.query_name()`, XYZ URL or `xyzservices.TileProvider` object), specify colormap (all supported by `matplotlib`) and specify black outline." ] }, { "cell_type": "markdown", "id": "798bf532", "metadata": {}, "source": [ "