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", "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-likeOrdered 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.Iconthe 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.
colorstrStroke color
weightintStroke 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.
fillColorstrFill color. Defaults to the value of the color option
fillOpacityfloat (default 0.5)Fill opacity.
style_functioncallableFunction mapping a GeoJson Feature to a style dict
.
Style properties folium.vector_layers.path_options()
GeoJson features GeoDataFrame.__geo_interface__
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:
captionstringCustom 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-likeA 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 10Maximum 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
.
**kwargsdictAdditional options to be passed on to the folium object.
Returns:
mfolium.folium.Mapfolium Map
instance
>>> import geodatasets
>>> df = geopandas.read_file(
... geodatasets.get_path("geoda.chicago_health")
... )
>>> df.head(2)
ComAreaID ... geometry
0 35 ... POLYGON ((-87.60914 41.84469, -87.60915 41.844...
1 36 ... POLYGON ((-87.59215 41.81693, -87.59231 41.816...
[2 rows x 87 columns]
>>> df.explore("Pop2012", cmap="Blues")