API

Contents

API#

Matplotlib#

figanos.matplotlib.plot.gdfmap(df: ~geopandas.geodataframe.GeoDataFrame, df_col: str, ax: ~cartopy.mpl.geoaxes.GeoAxes | None = None, fig_kw: dict[str, ~typing.Any] | None = None, plot_kw: dict[str, ~typing.Any] | None = None, projection: ~cartopy.crs.Projection = <Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, features: list[str] | dict[str, dict[str, ~typing.Any]] | None = None, cmap: str | ~matplotlib.colors.Colormap | None = None, levels: int | list[int | float] | None = None, divergent: bool | int | float = False, cbar: bool = True, frame: bool = False) Axes[source]

Create a map plot from geometries.

Parameters#

dfgeopandas.GeoDataFrame

Dataframe containing the geometries and the data to plot. Must have a column named ‘geometry’.

df_colstr

Name of the column of ‘df’ containing the data to plot using the colorscale.

axcartopy.mpl.geoaxes.GeoAxes or cartopy.mpl.geoaxes.GeoaxesSubplot, optional

Matplotlib axis built with a projection, on which to plot.

fig_kwdict, optional

Arguments to pass to plt.figure().

plot_kwdict, optional

Arguments to pass to the GeoDataFrame.plot() method.

projectionccrs.Projection

The projection to use, taken from the cartopy.crs options. Ignored if ax is not None.

featureslist or dict, optional

Features to use, as a list or a nested dict containing kwargs. Options are the predefined features from cartopy.feature: [‘coastline’, ‘borders’, ‘lakes’, ‘land’, ‘ocean’, ‘rivers’, ‘states’].

cmapmatplotlib.colors.Colormap or str

Colormap to use. If str, can be a matplotlib or name of the file of an IPCC colormap (see data/ipcc_colors). If None, look for common variables (from data/ipcc_colors/varaibles_groups.json) in the name of df_col and use corresponding colormap, aligned with the IPCC visual style guide 2022 (https://www.ipcc.ch/site/assets/uploads/2022/09/IPCC_AR6_WGI_VisualStyleGuide_2022.pdf).

levelsint or list, optional

Number of levels or list of level boundaries (in data units) to use to divide the colormap.

divergentbool or int or float

If int or float, becomes center of cmap. Default center is 0.

cbarbool

Show colorbar. Default ‘True’.

framebool

Show or hide frame. Default False.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.gridmap(data: dict[str, ~typing.Any] | ~xarray.core.dataarray.DataArray | ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes | None = None, use_attrs: dict[str, ~typing.Any] | None = None, fig_kw: dict[str, ~typing.Any] | None = None, plot_kw: dict[str, ~typing.Any] | None = None, projection: ~cartopy.crs.Projection = <Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, transform: ~cartopy.crs.Projection | None = None, features: list[str] | dict[str, dict[str, ~typing.Any]] | None = None, geometries_kw: dict[str, ~typing.Any] | None = None, contourf: bool = False, cmap: str | ~matplotlib.colors.Colormap | None = None, levels: int | list | ~numpy.ndarray | None = None, divergent: bool | int | float = False, show_time: bool | str | int | tuple[float, float] = False, frame: bool = False) Axes[source]

Create map from 2D data.

Parameters#

datadict, DataArray or Dataset

Input data do plot. If dictionary, must have only one entry.

axmatplotlib axis, optional

Matplotlib axis on which to plot, with the same projection as the one specified.

use_attrsdict, optional

Dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘title’: ‘description’, ‘cbar_label’: ‘long_name’, ‘cbar_units’: ‘units’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.figure().

plot_kw: dict, optional

Arguments to pass to the xarray.plot.pcolormesh() or ‘xarray.plot.contourf()’ function.

projectionccrs.Projection

The projection to use, taken from the cartopy.crs options. Ignored if ax is not None.

transformccrs.Projection, optional

Transform corresponding to the data coordinate system. If None, an attempt is made to find dimensions matching ccrs.PlateCarree() or ccrs.RotatedPole().

featureslist or dict, optional

Features to use, as a list or a nested dict containing kwargs. Options are the predefined features from cartopy.feature: [‘coastline’, ‘borders’, ‘lakes’, ‘land’, ‘ocean’, ‘rivers’, ‘states’].

geometries_kwdict, optional

Arguments passed to cartopy ax.add_geometry() which adds given geometries (GeoDataFrame geometry) to axis.

contourfbool

By default False, use plt.pcolormesh(). If True, use plt.contourf().

cmapmatplotlib.colors.Colormap or str, optional

Colormap to use. If str, can be a matplotlib or name of the file of an IPCC colormap (see data/ipcc_colors). If None, look for common variables (from data/ipcc_colors/varaibles_groups.json) in the name of the DataArray or its ‘history’ attribute and use corresponding colormap, aligned with the IPCC visual style guide 2022 (https://www.ipcc.ch/site/assets/uploads/2022/09/IPCC_AR6_WGI_VisualStyleGuide_2022.pdf).

levelsint, list, np.ndarray, optional

Number of levels to divide the colormap into or list of level boundaries (in data units).

divergentbool or int or float

If int or float, becomes center of cmap. Default center is 0.

show_timebool, tuple, string or int.

If True, show time (as date) at the bottom right of the figure. Can be a tuple of axis coordinates (0 to 1, as a fraction of the axis length) representing the location of the text. If a string or an int, the same values as those of the ‘loc’ parameter of matplotlib’s legends are accepted.

Location String

Location Code

‘upper right’

1

‘upper left’

2

‘lower left’

3

‘lower right’

4

‘right’

5

‘center left’

6

‘center right’

7

‘lower center’

8

‘upper center’

9

‘center’

10

framebool

Show or hide frame. Default False.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.hatchmap(data: dict[str, ~typing.Any] | ~xarray.core.dataarray.DataArray | ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes | None = None, use_attrs: dict[str, ~typing.Any] | None = None, fig_kw: dict[str, ~typing.Any] | None = None, plot_kw: dict[str, ~typing.Any] | None = None, projection: ~cartopy.crs.Projection = <Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, transform: ~cartopy.crs.Projection | None = None, features: list[str] | dict[str, dict[str, ~typing.Any]] | None = None, geometries_kw: dict[str, ~typing.Any] | None = None, levels: int | None = None, legend_kw: dict[str, ~typing.Any] | None = None, show_time: bool | str | int | tuple[float, float] = False, frame: bool = False) Axes[source]

Create map of hatches from 2D data.

Parameters#

datadict, DataArray or Dataset

Input data do plot.

axmatplotlib axis, optional

Matplotlib axis on which to plot, with the same projection as the one specified.

use_attrsdict, optional

Dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘title’: ‘description’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.figure().

plot_kw: dict, optional

Arguments to pass to ‘xarray.plot.contourf()’ function. If ‘data’ is a dictionary, can be a nested dictionary with the same keys as ‘data’.

projectionccrs.Projection

The projection to use, taken from the cartopy.ccrs options. Ignored if ax is not None.

transformccrs.Projection, optional

Transform corresponding to the data coordinate system. If None, an attempt is made to find dimensions matching ccrs.PlateCarree() or ccrs.RotatedPole().

featureslist or dict, optional

Features to use, as a list or a nested dict containing kwargs. Options are the predefined features from cartopy.feature: [‘coastline’, ‘borders’, ‘lakes’, ‘land’, ‘ocean’, ‘rivers’, ‘states’].

geometries_kwdict, optional

Arguments passed to cartopy ax.add_geometry() which adds given geometries (GeoDataFrame geometry) to axis.

legend_kwdict, optional

Arguments to pass to ax.legend().

show_timebool, tuple, string or int.

If True, show time (as date) at the bottom right of the figure. Can be a tuple of axis coordinates (0 to 1, as a fraction of the axis length) representing the location of the text. If a string or an int, the same values as those of the ‘loc’ parameter of matplotlib’s legends are accepted.

Location String

Location Code

‘upper right’

1

‘upper left’

2

‘lower left’

3

‘lower right’

4

‘right’

5

‘center left’

6

‘center right’

7

‘lower center’

8

‘upper center’

9

‘center’

10

framebool

Show or hide frame. Default False.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.heatmap(data: DataArray | Dataset | dict[str, Any], ax: Axes | None = None, use_attrs: dict[str, Any] | None = None, fig_kw: dict[str, Any] | None = None, plot_kw: dict[str, Any] | None = None, transpose: bool = False, cmap: str | Colormap | None = 'RdBu', divergent: bool | int | float = False) Axes[source]

Create heatmap from a DataArray.

Parameters#

datadict or DataArray or Dataset

Input data do plot. If dictionary, must have only one entry.

axmatplotlib axis, optional

Matplotlib axis on which to plot, with the same projection as the one specified.

use_attrsdict, optional

Dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘cbar_label’: ‘long_name’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.figure().

plot_kwdict, optional

Arguments to pass to the ‘seaborn.heatmap()’ function. If ‘data’ is a dictionary, can be a nested dictionary with the same key as ‘data’.

transposebool

If true, the 2D data will be transposed, so that the original x-axis becomes the y-axis and vice versa.

cmapmatplotlib.colors.Colormap or str, optional

Colormap to use. If str, can be a matplotlib or name of the file of an IPCC colormap (see data/ipcc_colors). If None, look for common variables (from data/ipcc_colors/variables_groups.json) in the name of the DataArray or its ‘history’ attribute and use corresponding colormap, aligned with the IPCC Visual Style Guide 2022 (https://www.ipcc.ch/site/assets/uploads/2022/09/IPCC_AR6_WGI_VisualStyleGuide_2022.pdf).

divergentbool or int or float

If int or float, becomes center of cmap. Default center is 0.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.partition(data: DataArray | Dataset, ax: Axes | None = None, start_year: str | None = None, show_num: bool = True, fill_kw: dict[str, Any] | None = None, line_kw: dict[str, Any] | None = None, fig_kw: dict[str, Any] | None = None, legend_kw: dict[str, Any] | None = None) Axes[source]

Figure of the partition of total uncertainty by components.

Uncertainty fractions can be computed with xclim (https://xclim.readthedocs.io/en/stable/api.html#uncertainty-partitioning). Make sure the use fraction=True in the xclim function call.

Parameters#

data: xr.DataArray or xr.Dataset

Variance over time of the different components of uncertainty. Output of a xclim.ensembles._partitioning function.

axmatplotlib axis, optional

Matplotlib axis on which to plot

start_year: str

If None, the x-axis will be the time in year. If str, the x-axis will show the number of year since start_year.

show_num: bool

If True, show the number of elements for each uncertainty components in parenthesis in the legend. data should have attributes named after the components with a list its the elements.

fill_kw: dict

Keyword arguments passed to ax.fill_between. It is possible to pass a dictionary of keywords for each component (uncertainty coordinates).

line_kw: dict

Keyword arguments passed to ax.plot for the lines in between the components. The default is {color=”k”, lw=2}. We recommend always using lw>=2.

fig_kw: dict

Keyword arguments passed to plt.subplots.

legend_kw: dict

Keyword arguments passed to ax.legend.

Returns#

mpl.axes.Axes

figanos.matplotlib.plot.scattermap(data: dict[str, ~typing.Any] | ~xarray.core.dataarray.DataArray | ~xarray.core.dataset.Dataset, ax: ~matplotlib.axes._axes.Axes | None = None, use_attrs: dict[str, ~typing.Any] | None = None, fig_kw: dict[str, ~typing.Any] | None = None, plot_kw: dict[str, ~typing.Any] | None = None, projection: ~cartopy.crs.Projection = <Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, transform: ~cartopy.crs.Projection | None = <Projected CRS: +proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to ...> Name: unknown Axis Info [cartesian]: - E[east]: Easting (unknown) - N[north]: Northing (unknown) - h[up]: Ellipsoidal height (metre) Area of Use: - undefined Coordinate Operation: - name: unknown - method: Equidistant Cylindrical Datum: Unknown based on WGS 84 ellipsoid - Ellipsoid: WGS 84 - Prime Meridian: Greenwich, features: list[str] | dict[str, dict[str, ~typing.Any]] | None = None, geometries_kw: dict[str, ~typing.Any] | None = None, sizes: str | bool | None = None, size_range: tuple = (10, 60), cmap: str | ~matplotlib.colors.Colormap | None = None, levels: int | None = None, divergent: bool | int | float = False, legend_kw: dict[str, ~typing.Any] | None = None, show_time: bool | str | int | tuple[float, float] = False, frame: bool = False) Axes[source]

Make a scatter plot of georeferenced data on a map.

Parameters#

datadict, DataArray or Dataset

Input data do plot. If dictionary, must have only one entry.

axmatplotlib axis, optional

Matplotlib axis on which to plot, with the same projection as the one specified.

use_attrsdict, optional

Dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘title’: ‘description’, ‘cbar_label’: ‘long_name’, ‘cbar_units’: ‘units’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.figure().

plot_kwdict, optional

Arguments to pass to plt.scatter(). If ‘data’ is a dictionary, can be a dictionary with the same key as ‘data’.

projectionccrs.Projection

The projection to use, taken from the cartopy.crs options. Ignored if ax is not None.

transformccrs.Projection, optional

Transform corresponding to the data coordinate system. If None, an attempt is made to find dimensions matching ccrs.PlateCarree() or ccrs.RotatedPole().

featureslist or dict, optional

Features to use, as a list or a nested dict containing kwargs. Options are the predefined features from cartopy.feature: [‘coastline’, ‘borders’, ‘lakes’, ‘land’, ‘ocean’, ‘rivers’, ‘states’].

geometries_kwdict, optional

Arguments passed to cartopy ax.add_geometry() which adds given geometries (GeoDataFrame geometry) to axis.

sizesbool or str, optional

String name of the coordinate to use for determining point size. If True, use the same data as in the colorbar.

size_rangetuple

Tuple of the minimum and maximum size of the points.

cmapmatplotlib.colors.Colormap or str, optional

Colormap to use. If str, can be a matplotlib or name of the file of an IPCC colormap (see data/ipcc_colors). If None, look for common variables (from data/ipcc_colors/variables_groups.json) in the name of the DataArray or its ‘history’ attribute and use corresponding colormap, aligned with the IPCC Visual Style Guide 2022 (https://www.ipcc.ch/site/assets/uploads/2022/09/IPCC_AR6_WGI_VisualStyleGuide_2022.pdf).

levelsint, optional

Number of levels to divide the colormap into.

divergentbool or int or float

If int or float, becomes center of cmap. Default center is 0.

legend_kwdict, optional
Arguments to pass to plt.legend(). Some defaults {“loc”: “lower left”, “facecolor”: “w”, “framealpha”: 1,

“edgecolor”: “w”, “bbox_to_anchor”: (-0.05, 0)}

show_timebool, tuple, string or int.

If True, show time (as date) at the bottom right of the figure. Can be a tuple of axis coordinates (0 to 1, as a fraction of the axis length) representing the location of the text. If a string or an int, the same values as those of the ‘loc’ parameter of matplotlib’s legends are accepted.

Location String

Location Code

‘upper right’

1

‘upper left’

2

‘lower left’

3

‘lower right’

4

‘right’

5

‘center left’

6

‘center right’

7

‘lower center’

8

‘upper center’

9

‘center’

10

framebool

Show or hide frame. Default False.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.stripes(data: dict[str, Any] | DataArray | Dataset, ax: Axes | None = None, fig_kw: dict[str, Any] | None = None, divide: int | None = None, cmap: str | Colormap | None = None, cmap_center: int | float = 0, cbar: bool = True, cbar_kw: dict[str, Any] | None = None) Axes[source]

Create stripes plot with or without multiple scenarios.

Parameters#

datadict or DataArray or Dataset

Data to plot. If a dictionary of xarray objects, each will correspond to a scenario.

axmatplotlib.axes.Axes, optional

Matplotlib axis on which to plot.

fig_kw: dict, optional

Arguments to pass to plt.subplots(). Only works if ax is not provided.

divideint, optional

Year at which the plot is divided into scenarios. If not provided, the horizontal separators will extend over the full time axis.

cmapmatplotlib.colors.Colormap or str, optional

Colormap to use. If str, can be a matplotlib or name of the file of an IPCC colormap (see data/ipcc_colors). If None, look for common variables (from data/ipcc_colors/variables_groups.json) in the name of the DataArray or its ‘history’ attribute and use corresponding diverging colormap, aligned with the IPCC Visual Style Guide 2022 (https://www.ipcc.ch/site/assets/uploads/2022/09/IPCC_AR6_WGI_VisualStyleGuide_2022.pdf).

cmap_centerint or float

Center of the colormap in data coordinates. Default is 0.

cbarbool

Show colorbar.

cbar_kwdict, optional

Arguments to pass to plt.colorbar.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.taylordiagram(data: DataArray | dict[str, DataArray], plot_kw: dict[str, Any] | None = None, fig_kw: dict[str, Any] | None = None, std_range: tuple = (0, 1.5), contours: int | None = 4, contours_kw: dict[str, Any] | None = None, legend_kw: dict[str, Any] | None = None, std_label: str | None = None, corr_label: str | None = None)[source]

Build a Taylor diagram.

Based on the following code: https://gist.github.com/ycopin/3342888.

Parameters#

dataxr.DataArray or dict

DataArray or dictionary of DataArrays created by xclim.sdba.measures.taylordiagram, each corresponding to a point on the diagram. The dictionary keys will become their labels.

plot_kwdict, optional

Arguments to pass to the plot() function. Changes how the markers look. If ‘data’ is a dictionary, must be a nested dictionary with the same keys as ‘data’.

fig_kwdict, optional

Arguments to pass to plt.figure().

std_rangetuple

Range of the x and y axes, in units of the highest standard deviation in the data.

contoursint, optional

Number of rsme contours to plot.

contours_kwdict, optional

Arguments to pass to plt.contour() for the rmse contours.

legend_kwdict, optional

Arguments to pass to plt.legend().

std_labelstr, optional

Label for the standard deviation (x and y) axes.

corr_labelstr, optional

Label for the correlation axis.

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.timeseries(data: dict[str, Any] | DataArray | Dataset, ax: Axes | None = None, use_attrs: dict[str, Any] | None = None, fig_kw: dict[str, Any] | None = None, plot_kw: dict[str, Any] | None = None, legend: str = 'lines', show_lat_lon: bool | str | int | tuple[float, float] = True) Axes[source]

Plot time series from 1D Xarray Datasets or DataArrays as line plots.

Parameters#

datadict or Dataset/DataArray

Input data to plot. It can be a DataArray, Dataset or a dictionary of DataArrays and/or Datasets.

axmatplotlib.axes.Axes, optional

Matplotlib axis on which to plot.

use_attrsdict, optional

A dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘title’: ‘description’, ‘ylabel’: ‘long_name’, ‘yunits’: ‘units’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.subplots(). Only works if ax is not provided.

plot_kwdict, optional

Arguments to pass to the plot() function. Changes how the line looks. If ‘data’ is a dictionary, must be a nested dictionary with the same keys as ‘data’.

legendstr (default ‘lines’) or dict
‘full’ (lines and shading), ‘lines’ (lines only), ‘in_plot’ (end of lines),

‘edge’ (out of plot), ‘facetgrid’ under figure, ‘none’ (no legend). If dict, arguments to pass to ax.legend().

show_lat_lonbool, tuple, str or int

If True, show latitude and longitude at the bottom right of the figure. Can be a tuple of axis coordinates (from 0 to 1, as a fraction of the axis length) representing the location of the text. If a string or an int, the same values as those of the ‘loc’ parameter of matplotlib’s legends are accepted.

Location String

Location Code

‘upper right’

1

‘upper left’

2

‘lower left’

3

‘lower right’

4

‘right’

5

‘center left’

6

‘center right’

7

‘lower center’

8

‘upper center’

9

‘center’

10

Returns#

matplotlib.axes.Axes

figanos.matplotlib.plot.violin(data: dict[str, Any] | DataArray | Dataset, ax: Axes | None = None, use_attrs: dict[str, Any] | None = None, fig_kw: dict[str, Any] | None = None, plot_kw: dict[str, Any] | None = None, color: str | int | list[str | int] | None = None) Axes[source]

Make violin plot using seaborn.

Parameters#

datadict or Dataset/DataArray

Input data to plot. If a dict, must contain DataArrays and/or Datasets.

axmatplotlib.axes.Axes, optional

Matplotlib axis on which to plot.

use_attrsdict, optional

A dict linking a plot element (key, e.g. ‘title’) to a DataArray attribute (value, e.g. ‘Description’). Default value is {‘title’: ‘description’, ‘ylabel’: ‘long_name’, ‘yunits’: ‘units’}. Only the keys found in the default dict can be used.

fig_kwdict, optional

Arguments to pass to plt.subplots(). Only works if ax is not provided.

plot_kwdict, optional

Arguments to pass to the seaborn.violinplot() function.

colorstr, int or list, optional

Unique color or list of colors to use. Integers point to the applied stylesheet’s colors, in zero-indexed order. Passing ‘color’ or ‘palette’ in plot_kw overrides this argument.

Returns#

matplotlib.axes.Axes