Note
Interactive mapping#
Alongside static plots, geopandas can create interactive maps based on the folium library.
Creating maps for interactive exploration mirrors the API of static plots in an explore() method of a GeoSeries or GeoDataFrame.
Loading some example data:
[1]:
import geopandas
import geodatasets
nybb = geopandas.read_file(geodatasets.get_path("nybb"))
chicago = geopandas.read_file(geodatasets.get_path("geoda.chicago_commpop"))
groceries = geopandas.read_file(geodatasets.get_path("geoda.groceries")).explode(ignore_index=True)
The simplest option is to use GeoDataFrame.explore():
[2]:
nybb.explore()
[2]:
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.
Note
Note that the GeoDataFrame needs to have a CRS set if you want to use background tiles.
[3]:
nybb.explore(
column="BoroName", # make choropleth based on "BoroName" column
tooltip="BoroName", # show "BoroName" value in tooltip (on hover)
popup=True, # show all values in popup (on click)
tiles="CartoDB positron", # use "CartoDB positron" tiles
cmap="Set1", # use "Set1" matplotlib colormap
style_kwds=dict(color="black"), # use black outline
)
[3]: