Maps.set_frame#
- Maps.set_frame(rounded=0, gdf=None, countries=None, **kwargs)#
Set the properties of the map boundary and the background patch.
use rounded kwarg to get a rectangle border with rounded corners
use gdf kwarg to use geopandas.GeoDataFrame geometries as map-border
use countries kwarg to set the map-border to one (or more) countries.
All additional kwargs are used to style the border-line.
- Parameters:
rounded (float, optional) – If provided, use a rectangle with rounded corners as map boundary line. The corners will be rounded with respect to the provided fraction (0=no rounding, 1=max. radius). The default is None.
gdf (geopandas.GeoDataFrame or path) –
A geopandas.GeoDataFrame that contains geometries that should be used as map-frame.
If a path (string or pathlib.Path) is provided, the corresponding file will be read as a geopandas.GeoDataFrame and the boundaries of the contained geometries will be used as map-boundary.
The default is None.
kwargs –
Additional kwargs to style the boundary line (e.g. the spine) and the background patch
Possible args for the boundary-line:
”edgecolor” or “ec”: The line color
”linewidth” or “lw”: The line width
”linestyle” or “ls”: The line style
”path_effects”: A list of path-effects to apply to the line
Possible args for the background-patch:
”facecolor” or “fc”: The color of the background patch
set_extent (bool, optional) – Only relevant if gdf is used. If True, the map-extent is set to the extent of the provided geometry. The default is True.
scale (int, optional) – Only relevant if countries is used. The scale factor of the used NaturalEarth dataset. Must be one of [10, 50, 110]. The default is 50.
Examples
>>> m = Maps() >>> m.add_feature.preset.ocean() >>> m.set_frame(fc="r", ec="b", lw=3, rounded=.2)
Customize the map-boundary style
>>> import matplotlib.patheffects as pe >>> m = Maps() >>> m.add_feature.preset.ocean(fc="k") >>> m.set_frame( >>> facecolor=(.8, .8, 0, .5), edgecolor="w", linewidth=2, >>> rounded=.5, >>> path_effects=[pe.withStroke(linewidth=7, foreground="m")])
Set the map-boundary to a custom polygon (in this case the boarder of Austria)
>>> m = Maps() >>> m.add_feature.preset.land(fc="k") >>> # Get a GeoDataFrame with all country-boarders from NaturalEarth >>> gdf = m.add_feature.cultural.admin_0_countries.get_gdf() >>> # set the map-boundary to the Austrian country-boarder >>> m.set_frame(gdf = gdf[gdf.NAME=="Austria"])
Set the map-boundary to the country-border of Austria and Italy
>>> m = Maps(facecolor="0.4") >>> m.set_frame(countries=["Austria", "Italy"], ec="r", lw=2, fc="k")