geopandas.GeoDataFrame.explore

GeoDataFrame.explore(*args, **kwargs)

Interactive map based on folium/leaflet.jsInteractive map based on GeoPandas and folium/leaflet.js

Generate an interactive leaflet map based on GeoDataFrame

Parameters
columnstr, np.array, pd.Series (default None)

The name of the dataframe column, numpy.array, or pandas.Series to be plotted. If numpy.array or pandas.Series are used then it must have same length as dataframe.

cmapstr, matplotlib.Colormap, branca.colormap or function (default None)

The name of a colormap recognized by matplotlib, a list-like of colors, matplotlib.colors.Colormap, a branca.colormap.ColorMap or function that returns a named color or hex based on the column value, e.g.:

def my_colormap(value):  # scalar value defined in 'column'
    if value > 1:
        return "green"
    return "red"
colorstr, array-like (default None)

Named color or a list-like of colors (named or hex).

mfolium.Map (default None)

Existing map instance on which to draw the plot.

tilesstr, xyzservices.TileProvider (default ‘OpenStreetMap Mapnik’)

Map tileset to use. Can choose from the list supported by folium, query a xyzservices.TileProvider by a name from xyzservices.providers, pass xyzservices.TileProvider object or pass custom XYZ URL. The current list of built-in providers (when xyzservices is not available):

["OpenStreetMap", "Stamen Terrain", “Stamen Toner", “Stamen Watercolor" "CartoDB positron", “CartoDB dark_matter"]

You can pass a custom tileset to Folium by passing a Leaflet-style URL to the tiles parameter: http://{s}.yourtiles.com/{z}/{x}/{y}.png. Be sure to check their terms and conditions and to provide attribution with the attr keyword.

attrstr (default None)

Map tile attribution; only required if passing custom tile URL.

tooltipbool, str, int, list (default True)

Display GeoDataFrame attributes when hovering over the object. True includes all columns. False removes tooltip. Pass string or list of strings to specify a column(s). Integer specifies first n columns to be included. Defaults to True.

popupbool, str, int, list (default False)

Input GeoDataFrame attributes for object displayed when clicking. True includes all columns. False removes popup. Pass string or list of strings to specify a column(s). Integer specifies first n columns to be included. Defaults to False.

highlightbool (default True)

Enable highlight functionality when hovering over a geometry.

categoricalbool (default False)

If False, cmap will reflect numerical values of the column being plotted. For non-numerical columns, this will be set to True.

legendbool (default True)

Plot a legend in choropleth plots. Ignored if no column is given.

schemestr (default None)

Name of a choropleth classification scheme (requires mapclassify >= 2.4.0). A mapclassify.classify() will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds.

kint (default 5)

Number of classes

vminNone or float (default None)

Minimum value of cmap. If None, the minimum data value in the column to be plotted is used.

vmaxNone or float (default None)

Maximum value of cmap. If None, the maximum data value in the column to be plotted is used.

widthpixel int or percentage string (default: ‘100%’)

Width of the folium Map. If the argument m is given explicitly, width is ignored.

heightpixel int or percentage string (default: ‘100%’)

Height of the folium Map. If the argument m is given explicitly, height is ignored.

categorieslist-like

Ordered list-like object of categories to be used for categorical plot.

classification_kwdsdict (default None)

Keyword arguments to pass to mapclassify

control_scalebool, (default True)

Whether to add a control scale on the map.

marker_typestr, folium.Circle, folium.CircleMarker, folium.Marker (default None)

Allowed string options are (‘marker’, ‘circle’, ‘circle_marker’). Defaults to folium.CircleMarker.

marker_kwds: dict (default {})

Additional keywords to be passed to the selected marker_type, e.g.:

radiusfloat (default 2 for circle_marker and 50 for circle))

Radius of the circle, in meters (for circle) or pixels (for circle_marker).

fillbool (default True)

Whether to fill the circle or circle_marker with color.

iconfolium.map.Icon

the folium.map.Icon object to use to render the marker.

draggablebool (default False)

Set to True to be able to drag the marker around the map.

style_kwdsdict (default {})

Additional style to be passed to folium style_function:

strokebool (default True)

Whether to draw stroke along the path. Set it to False to disable borders on polygons or circles.

colorstr

Stroke color

weightint

Stroke width in pixels

opacityfloat (default 1.0)

Stroke opacity

fillboolean (default True)

Whether to fill the path with color. Set it to False to disable filling on polygons or circles.

fillColorstr

Fill color. Defaults to the value of the color option

fillOpacityfloat (default 0.5)

Fill opacity.

style_functioncallable

Function mapping a GeoJson Feature to a style dict.

e.g.:

lambda x: {"color":"red" if x["properties"]["gdp_md_est"]<10**6
                             else "blue"}

Plus all supported by folium.vector_layers.path_options(). See the documentation of folium.features.GeoJson for details.

highlight_kwdsdict (default {})

Style to be passed to folium highlight_function. Uses the same keywords as style_kwds. When empty, defaults to {"fillOpacity": 0.75}.

tooltip_kwdsdict (default {})

Additional keywords to be passed to folium.features.GeoJsonTooltip, e.g. aliases, labels, or sticky.

popup_kwdsdict (default {})

Additional keywords to be passed to folium.features.GeoJsonPopup, e.g. aliases or labels.

legend_kwdsdict (default {})

Additional keywords to be passed to the legend.

Currently supported customisation:

captionstring

Custom caption of the legend. Defaults to the column name.

Additional accepted keywords when scheme is specified:

colorbarbool (default True)

An option to control the style of the legend. If True, continuous colorbar will be used. If False, categorical legend will be used for bins.

scalebool (default True)

Scale bins along the colorbar axis according to the bin edges (True) or use the equal length for each bin (False)

fmtstring (default “{:.2f}”)

A formatting specification for the bin edges of the classes in the legend. For example, to have no decimals: {"fmt": "{:.0f}"}. Applies if colorbar=False.

labelslist-like

A list of legend labels to override the auto-generated labels. Needs to have the same number of elements as the number of classes (k). Applies if colorbar=False.

intervalboolean (default False)

An option to control brackets from mapclassify legend. If True, open/closed interval brackets are shown in the legend. Applies if colorbar=False.

max_labelsint, default 10

Maximum number of colorbar tick labels (requires branca>=0.5.0)

map_kwdsdict (default {})

Additional keywords to be passed to folium Map, e.g. dragging, or scrollWheelZoom.

**kwargsdict

Additional options to be passed on to the folium object.

Returns
mfolium.folium.Map

folium Map instance

Examples

>>> df = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
>>> df.head(2)  
    pop_est      continent                      name iso_a3  gdp_md_est                                           geometry
0     920938        Oceania                      Fiji    FJI      8374.0  MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1   53950935         Africa                  Tanzania    TZA    150600.0  POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
>>> df.explore("pop_est", cmap="Blues")