comparison.ComparerPlotter

comparison.ComparerPlotter(self, comparer)

Plotter class for Comparer

Examples

>>> cmp.plot.scatter()
>>> cmp.plot.timeseries()
>>> cmp.plot.hist()
>>> cmp.plot.kde()
>>> cmp.plot.qq()
>>> cmp.plot.box()

Methods

Name Description
box Make a box plot of model data and observations.
hist Plot histogram of model data and observations.
kde Plot kde (kernel density estimates of distributions) of model data and observations.
qq Make quantile-quantile (q-q) plot of model data and observations.
residual_hist plot histogram of residual values
scatter Scatter plot tailored for model-observation comparison.
taylor Taylor diagram for model skill comparison.
timeseries Timeseries plot showing compared data: observation vs modelled

box

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

Make a box plot of model data and observations.

Wraps pandas.DataFrame boxplot() method.

Parameters

Name Type Description Default
ax matplotlib.axes.Axes axes to plot on, by default None None
title str plot title, default: [observation name] None
figsize tuple figure size, by default None None
**kwargs other keyword arguments to df.boxplot() {}

Returns

Name Type Description
matplotlib axes

Examples

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

See also

pandas.DataFrame.boxplot matplotlib.pyplot.boxplot

hist

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

Plot histogram of model data and 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: [model name] vs [observation name] None
ax matplotlib.axes.Axes axes to plot on, by default None None
figsize tuple figure size, by default None None
density bool If True, draw and return a probability density True
alpha float alpha transparency fraction, by default 0.5 0.5
**kwargs other keyword arguments to df.plot.hist() {}

Returns

Name Type Description
matplotlib axes

See also

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

kde

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

Plot kde (kernel density estimates of distributions) of model data and observations.

Wraps pandas.DataFrame kde() method.

Parameters

Name Type Description Default
ax matplotlib.axes.Axes axes to plot on, by default None None
title str plot title, default: “KDE plot for [observation name]” None
figsize tuple figure size, by default None None
**kwargs other keyword arguments to df.plot.kde() {}

Returns

Name Type Description
matplotlib.axes.Axes

Examples

>>> cmp.plot.kde()
>>> cmp.plot.kde(bw_method=0.3)
>>> cmp.plot.kde(ax=ax, bw_method='silverman')
>>> cmp.plot.kde(xlim=[0,None], title="Density plot");

See also

pandas.Series.plot.kde

qq

comparison.ComparerPlotter.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

>>> cmp.plot.qq()

residual_hist

comparison.ComparerPlotter.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 matplotlib.axes.Axes | list[matplotlib.axes.Axes] axes to plot on, by default None None
**kwargs other keyword arguments to plt.hist() {}

Returns

Name Type Description
matplotlib.axes.Axes | list[matplotlib.axes.Axes]

scatter

comparison.ComparerPlotter.scatter(
    model=None,
    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 model-observation comparison.

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 axes to plot on, by default None None
**kwargs other keyword arguments to plt.scatter() {}

Examples

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

taylor

comparison.ComparerPlotter.taylor(
    normalize_std=False,
    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
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

cmp.plot.taylor();

Notes

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

timeseries

comparison.ComparerPlotter.timeseries(
    title=None,
    ylim=None,
    ax=None,
    figsize=None,
    backend='matplotlib',
    **kwargs,
)

Timeseries plot showing compared data: observation vs modelled

Parameters

Name Type Description Default
title str plot title, by default None None
ylim (float, float) plot range for the model (ymin, ymax), by default None None
ax matplotlib.axes.Axes axes to plot on, by default None None
figsize (float, float) figure size, by default None None
backend str use “plotly” (interactive) or “matplotlib” backend, by default “matplotlib” 'matplotlib'
**kwargs other keyword arguments to fig.update_layout (plotly backend) {}

Returns

Name Type Description
matplotlib.axes.Axes or plotly.graph_objects.Figure