plot_stats
- eolab.georastertools.processing.stats.plot_stats(chartfile: str, stats_per_date: Dict[datetime, GeoDataFrame], stats: List[str] = ['min', 'max', 'mean', 'std'], index_name: str = 'ID', display: bool = False)[source]
Plot temporal statistics for geometries across multiple dates.
This function visualizes the evolution of specified statistics (e.g., “min”, “mean”) over time for different zones defined in the input GeoDataFrames. The output is saved as a chart file, and optionally displayed.
- Parameters:
chartfile (str) – Path to the file where the generated chart will be saved.
stats_per_date (Dict[datetime.datetime, gpd.GeoDataFrame]) – A dictionary mapping each date to a GeoDataFrame containing the statistics for that date. Each GeoDataFrame should include the specified index_name column and relevant statistics columns.
stats (List[str], optional) – A list of statistics to plot (e.g., “min”, “max”, “mean”, “std”). Defaults to [“min”, “max”, “mean”, “std”].
index_name (str, optional) – Name of the column in the GeoDataFrames that uniquely identifies the zones (e.g., region IDs). Defaults to ‘ID’.
display (bool, optional) – If True, the generated plot is displayed after saving. Defaults to False.
- Raises:
ValueError – If the specified index_name is not present in the combined GeoDataFrame.
Notes
The stats_per_date dictionary must be ordered or sortable by date to ensure proper time-series plotting.
Each GeoDataFrame in stats_per_date should have columns named in the format <prefix>.<stat> (e.g., “temperature.mean”).
Example
``` import geopandas as gpd import datetime from plot_tools import plot_stats
# Example input stats_per_date = {
datetime.datetime(2023, 1, 1): gpd.GeoDataFrame({…}), datetime.datetime(2023, 2, 1): gpd.GeoDataFrame({…}),
}
- plot_stats(
chartfile=”output_chart.png”, stats_per_date=stats_per_date, stats=[“mean”, “std”], index_name=”RegionID”, display=True
)
- Output:
Saves a time-series plot of the specified statistics as chartfile.
Optionally displays the plot if display=True.