plot_by_features#

geetools.ee_feature_collection.FeatureCollectionAccessor.plot_by_features(type='bar', featureId='system:index', properties=None, labels=None, colors=None, ax=None, **kwargs)#

Plot the values of a ee.FeatureCollection by feature.

Each feature property selected in properties will be plotted using the featureId as the x-axis. If no properties are provided, all properties will be plotted. If no featureId is provided, the "system:index" property will be used.

Warning

This function is a client-side function.

Parameters:
  • type (str) – The type of plot to use. Defaults to "bar". can be any type of plot from the python lib matplotlib.pyplot. If the one you need is missing open an issue!

  • featureId (str) – The property to use as the x-axis (name the features). Defaults to "system:index".

  • properties (list[str] | None) – A list of properties to plot. Defaults to all properties.

  • labels (list[str] | None) – A list of labels to use for plotting the properties. If not provided, the default labels will be used. It needs to match the properties’ length.

  • colors (list[str] | None) – A list of colors to use for plotting the properties. If not provided, the default colors from the matplotlib library will be used.

  • ax (matplotlib.axes.Axes | None) – The matplotlib axes to use. If not provided, the plot will be sent to a new figure.

  • kwargs – Additional arguments from the pyplot type selected.

Return type:

matplotlib.axes.Axes

See also

  • byFeatures: Get a dictionary with all property values for each feature.

  • plot_by_properties: Plot the values of a :py:class:`ee.FeatureCollection` by property.

  • plot_hist: Plot the histogram of a specific property.

  • plot: Plot the featureCollection on a map using the provided property.

Examples

import ee, geetools
from geetools.utils import initialize_documentation
from matplotlib import pyplot as plt

initialize_documentation()

# start a plot object from matplotlib library
fig, ax = plt.subplots(figsize=(10, 5))

# plot on this object the 10 first items of the FAO GAUL level 2 feature collection
# for each one of them (marked with it's "ADM0_NAME" property) we plot the value of the "ADM1_CODE" and "ADM2_CODE" properties
fc = ee.FeatureCollection("FAO/GAUL/2015/level2").limit(10)
fc.geetools.plot_by_features(featureId="ADM2_NAME", properties=["ADM1_CODE", "ADM2_CODE"], colors=["#61A0D4", "#D49461"], ax=ax)

# Modify the rotation of existing x-axis tick labels
for label in ax.get_xticklabels():
    label.set_rotation(45)
../../../_images/FeatureCollectionAccessor.plot_by_features_0_01.png