comparison.ComparerCollectionPlotter

comparison.ComparerCollectionPlotter(self, cc)

Plotter for ComparerCollection

Examples

>>> cc.plot.scatter()
>>> cc.plot.hist()
>>> cc.plot.kde()
>>> cc.plot.taylor()
>>> cc.plot.box()

Methods

Name Description
box Plot box plot of observations and model data.
hist Plot histogram of specific model and all observations.
kde Plot kernel density estimate of observation and model data.
qq Make quantile-quantile (q-q) plot of model data and observations.
residual_hist plot histogram of residual values
scatter Scatter plot tailored for comparing model output with observations.
taylor Taylor diagram for model skill comparison.

box

comparison.ComparerCollectionPlotter.box(
    ax=None,
    figsize=None,
    title=None,
    **kwargs,
)

Plot box plot of observations and model data.

Parameters

Name Type Description Default
ax Axes matplotlib axes, by default None None
figsize tuple width and height of the figure, by default None None
title str plot title, by default None None
**kwargs passed to pandas.DataFrame.plot.box() {}

Returns

Name Type Description
Axes matplotlib axes

Examples

>>> cc.plot.box()
>>> cc.plot.box(showmeans=True)
>>> cc.plot.box(ax=ax, title="Box plot")

hist

comparison.ComparerCollectionPlotter.hist(
    bins=100,
    *,
    model=None,
    title=None,
    density=True,
    alpha=0.5,
    ax=None,
    figsize=None,
    **kwargs,
)

Plot histogram of specific model and all observations.

Wraps pandas.DataFrame hist() method.

Parameters

Name Type Description Default
bins int number of bins, by default 100 100
title str plot title, default: observation name None
density bool If True, draw and return a probability density, by default True True
alpha float alpha transparency fraction, by default 0.5 0.5
ax matplotlib axes axes to plot on, by default None None
figsize tuple width and height of the figure, by default None None
**kwargs other keyword arguments to df.hist() {}

Returns

Name Type Description
matplotlib axes

Examples

>>> cc.plot.hist()
>>> cc.plot.hist(bins=100)

See also

pandas.Series.hist matplotlib.axes.Axes.hist

kde

comparison.ComparerCollectionPlotter.kde(
    ax=None,
    figsize=None,
    title=None,
    **kwargs,
)

Plot kernel density estimate of observation and model data.

Parameters

Name Type Description Default
ax Axes matplotlib axes, by default None None
figsize tuple width and height of the figure, by default None None
title str plot title, by default None None
**kwargs passed to pandas.DataFrame.plot.kde() {}

Returns

Name Type Description
Axes matplotlib axes

Examples

>>> cc.plot.kde()
>>> cc.plot.kde(bw_method=0.5)
>>> cc.plot.kde(bw_method='silverman')

qq

comparison.ComparerCollectionPlotter.qq(
    quantiles=None,
    *,
    title=None,
    ax=None,
    figsize=None,
    **kwargs,
)

Make quantile-quantile (q-q) plot of model data and observations.

Primarily used to compare multiple models.

Parameters

Name Type Description Default
quantiles int | Sequence[float] | None number of quantiles for QQ-plot, by default None and will depend on the scatter data length (10, 100 or 1000) if int, this is the number of points if sequence (list of floats), represents the desired quantiles (from 0 to 1) None
title str plot title, default: “Q-Q plot for [observation name]” None
ax matplotlib.axes.Axes axes to plot on, by default None None
figsize tuple figure size, by default None None
**kwargs other keyword arguments to plt.plot() {}

Returns

Name Type Description
matplotlib axes

Examples

>>> cc.plot.qq()

residual_hist

comparison.ComparerCollectionPlotter.residual_hist(
    bins=100,
    title=None,
    color=None,
    figsize=None,
    ax=None,
    **kwargs,
)

plot histogram of residual values

Parameters

Name Type Description Default
bins int specification of bins, by default 100 100
title str plot title, default: Residuals, [name] None
color str residual color, by default “#8B8D8E” None
figsize tuple figure size, by default None None
ax Axes | list[Axes] axes to plot on, by default None None
**kwargs other keyword arguments to plt.hist() {}

Returns

Name Type Description
Axes | list[Axes]

scatter

comparison.ComparerCollectionPlotter.scatter(
    bins=120,
    quantiles=None,
    fit_to_quantiles=False,
    show_points=None,
    show_hist=None,
    show_density=None,
    norm=None,
    backend='matplotlib',
    figsize=(8, 8),
    xlim=None,
    ylim=None,
    reg_method='ols',
    title=None,
    xlabel=None,
    ylabel=None,
    skill_table=None,
    ax=None,
    **kwargs,
)

Scatter plot tailored for comparing model output with observations.

Optionally, with density histogram.

Parameters

Name Type Description Default
bins int | float bins for the 2D histogram on the background. By default 120 bins. if int, represents the number of bins of 2D if float, represents the bin size if sequence (list of int or float), represents the bin edges 120
quantiles int | Sequence[float] | None number of quantiles for QQ-plot, by default None and will depend on the scatter data length (10, 100 or 1000); if int, this is the number of points; if sequence (list of floats), represents the desired quantiles (from 0 to 1) None
fit_to_quantiles bool by default the regression line is fitted to all data, if True, it is fitted to the quantiles which can be useful to represent the extremes of the distribution, by default False False
show_points (bool, int, float) Should the scatter points be displayed? None means: show all points if fewer than 1e4, otherwise show 1e4 sample points, by default None. float: fraction of points to show on plot from 0 to 1. e.g. 0.5 shows 50% of the points. int: if ‘n’ (int) given, then ‘n’ points will be displayed, randomly selected None
show_hist bool show the data density as a a 2d histogram, by default None None
show_density Optional[bool] show the data density as a colormap of the scatter, by default None. If both show_density and show_hist are None, then show_density is used by default. If number of points is less than 200, then show_density is False as default. For binning the data, the kword bins=Float is used. None
norm matplotlib.colors norm colormap normalization. If None, defaults to matplotlib.colors.PowerNorm(vmin=1, gamma=0.5) None
backend str use “plotly” (interactive) or “matplotlib” backend, by default “matplotlib” 'matplotlib'
figsize tuple width and height of the figure, by default (8, 8) (8, 8)
xlim tuple plot range for the observation (xmin, xmax), by default None None
ylim tuple plot range for the model (ymin, ymax), by default None None
reg_method str or bool method for determining the regression line “ols” : ordinary least squares regression “odr” : orthogonal distance regression, False : no regression line, by default “ols” 'ols'
title str plot title, by default None None
xlabel str x-label text on plot, by default None None
ylabel str y-label text on plot, by default None None
skill_table (str, List[str], bool) list of modelskill.metrics or boolean, if True then by default modelskill.options.metrics.list. This kword adds a box at the right of the scatter plot, by default False None
ax matplotlib axes axes to plot on, by default None None
**kwargs other keyword arguments to matplotlib.pyplot.scatter() {}

Examples

>>> cc.plot.scatter()
>>> cc.plot.scatter(bins=0.2, backend='plotly')
>>> cc.plot.scatter(show_points=False, title='no points')
>>> cc.plot.scatter(xlabel='all observations', ylabel='my model')
>>> cc.sel(model='HKZN_v2').plot.scatter(figsize=(10, 10))
>>> cc.sel(observations=['c2','HKNA']).plot.scatter()

taylor

comparison.ComparerCollectionPlotter.taylor(
    normalize_std=False,
    aggregate_observations=True,
    figsize=(7, 7),
    marker='o',
    marker_size=6.0,
    title='Taylor diagram',
)

Taylor diagram for model skill comparison.

Taylor diagram showing model std and correlation to observation in a single-quadrant polar plot, with r=std and theta=arccos(cc).

Parameters

Name Type Description Default
normalize_std bool plot model std normalized with observation std, default False False
aggregate_observations bool should multiple observations be aggregated before plotting (or shown individually), default True True
figsize tuple width and height of the figure (should be square), by default (7, 7) (7, 7)
marker str marker type e.g. “x”, “*“, by default”o” 'o'
marker_size float size of the marker, by default 6 6.0
title str title of the plot, by default “Taylor diagram” 'Taylor diagram'

Returns

Name Type Description
matplotlib.figure.Figure

Examples

>>> cc.plot.taylor()
>>> cc.sel(observation="c2").plot.taylor()
>>> cc.plot.taylor(start="2017-10-28", figsize=(5,5))

Notes

Copin, Y. (2018). https://gist.github.com/ycopin/3342888, Yannick Copin