layer_selector
- util.layer_selector(m, layers=None, draggable=True, exclude_layers=None, name=None, **kwargs)
A button-widget that can be used to select the displayed plot-layer.
Note
In general, layers are only drawn “on demand”, so if you switch to a layer that has not been shown yet, it needs to be drawn first.
Depending on the complexity (WebMaps, Overlays, very large datasets etc.) this might take a few seconds.
Once the layer has been drawn, it is cached and switching even between layers with many features should be fast.
If the extent of the map changes (e.g. pan/zoom) or new features are added to the layer, it will be re-drawn.
- Parameters:
layers (list or None, optional) –
A list of layer-names (or tuples of layer-names to combine) that are used in the selector. For details on how to use combined layers, check the docstring of m.show_layer()
If None, all available layers (except the “all” layer) are shown, and the layers are automatically updated whenever a new layer is created on the map. (check the ‘exclude_layers’ parameter for excluding specific layers) The default is None.
draggable (bool, optional) – Indicator if the widget should be draggable or not. The default is True.
exclude_layers (list or None) – A list of layer-names that should be excluded. Only relevant if layers=None is used. The default is None in which case only the “all” layer is excluded. (Same as exclude = [“all”]. Use exclude=[] to get all available layers.)
name (str) – The name of the slider (used to identify the object) If None, a unique identifier is used.
kwargs –
All additional arguments are passed to plt.legend
Some useful arguments are:
ncol: the number of columns to use
size: the size of the markers
fontsize: the fontsize of the labels
loc: the position of the widget with respect to the figure. Any combination of the strings [“upper”, “lower”] and [“left”, “right”, “center”] is possible.
bbox_to_anchor: offset from the loc-position in figure coordinates e.g.: (loc=”upper center”, bbox_to_anchor=(0.5, 1.1))
Examples
>>> from eomaps import Maps >>> m = Maps(layer="coastline") >>> m2 = m.new_layer(layer="ocean") >>> m.add_feature.preset.coastline() >>> m2.add_feature.preset.ocean() >>> s = m.util.layer_selector(loc="upper left") >>> s2 = m.util.layer_selector( >>> layers=["ocean", >>> (("ocean", .5), "coastline")], >>> loc="upper right")
To remove the widget (s), simply use:
>>> s.remove()
See also
Utilities.layer_slider
A slider widget to switch between layers.
Maps.show_layer
Set the currently visible layer.