scmdata.plotting

Plotting helpers for ScmRun

See the example notebook ‘plotting-with-seaborn.ipynb’ for usage examples

scmdata.plotting.inject_plotting_methods(cls)[source]

Inject the plotting methods

Parameters

cls – Target class

scmdata.plotting.lineplot(self, time_axis=None, **kwargs)[source]

Make a line plot via seaborn’s lineplot

If only a single unit is present, it will be used as the y-axis label. The axis object is returned so this can be changed by the user if desired.

Parameters
  • time_axis ({None, "year", "year-month", "days since 1970-01-01", "seconds since 1970-01-01"} # noqa: E501) –

    Time axis to use for the plot.

    If None, datetime.datetime objects will be used.

    If "year", the year of each time point will be used.

    If "year-month", the year plus (month - 0.5) / 12 will be used.

    If "days since 1970-01-01", the number of days since 1st Jan 1970 will be used (calculated using the datetime module).

    If "seconds since 1970-01-01", the number of seconds since 1st Jan 1970 will be used (calculated using the datetime module).

  • **kwargs – Keyword arguments to be passed to seaborn.lineplot. If none are passed, sensible defaults will be used.

Returns

Output of call to seaborn.lineplot

Return type

matplotlib.axes._subplots.AxesSubplot

scmdata.plotting.plumeplot(self, ax=None, quantiles_plumes=[((0.05, 0.95), 0.5), ((0.5,), 1.0)], hue_var='scenario', hue_label='Scenario', palette=None, style_var='variable', style_label='Variable', dashes=None, linewidth=2, time_axis=None, pre_calculated=False, quantile_over=('ensemble_member',))[source]

Make a plume plot, showing plumes for custom quantiles

Parameters
  • ax (matplotlib.axes._subplots.AxesSubplot) – Axes on which to make the plot

  • quantiles_plumes (list[tuple[tuple, float]]) – Configuration to use when plotting quantiles. Each element is a tuple, the first element of which is itself a tuple and the second element of which is the alpha to use for the quantile. If the first element has length two, these two elements are the quantiles to plot and a plume will be made between these two quantiles. If the first element has length one, then a line will be plotted to represent this quantile.

  • hue_var (str) – The column of self.meta which should be used to distinguish different hues.

  • hue_label (str) – Label to use in the legend for hue_var.

  • palette (dict) – Dictionary defining the colour to use for different values of hue_var.

  • style_var (str) – The column of self.meta which should be used to distinguish different styles.

  • style_label (str) – Label to use in the legend for style_var.

  • dashes (dict) – Dictionary defining the style to use for different values of style_var.

  • linewidth (float) – Width of lines to use (for quantiles which are not to be shown as plumes)

  • time_axis (str) – Time axis to use for the plot (see timeseries())

  • pre_calculated (bool) – Are the quantiles pre-calculated? If no, the quantiles will be calculated within this function. Pre-calculating the quantiles using ScmRun.quantiles_over() can lead to faster plotting if multiple plots are to be made with the same quantiles.

  • quantile_over (str, tuple[str]) – Columns of self.meta over which the quantiles should be calculated. Only used if pre_calculated is False.

Returns

Axes on which the plot was made and the legend items we have made (in case the user wants to move the legend to a different position for example)

Return type

matplotlib.axes._subplots.AxesSubplot, list

Examples

>>> scmrun = ScmRun(
...     data=np.random.random((10, 3)).T,
...     columns={
...         "model": ["a_iam"],
...         "climate_model": ["a_model"] * 5 + ["a_model_2"] * 5,
...         "scenario": ["a_scenario"] * 5 + ["a_scenario_2"] * 5,
...         "ensemble_member": list(range(5)) + list(range(5)),
...         "region": ["World"],
...         "variable": ["Surface Air Temperature Change"],
...         "unit": ["K"],
...     },
...     index=[2005, 2010, 2015],
... )

Plot the plumes, calculated over the different ensemble members.

>>> scmrun.plumeplot(quantile_over="ensemble_member")

Pre-calculate the quantiles, then plot

>>> summary_stats = ScmRun(
...     scmrun.quantiles_over("ensemble_member", quantiles=quantiles)
... )
>>> summary_stats.plumeplot(pre_calculated=True)

Note

scmdata is not a plotting library so this function is provided as is, with little testing. In some ways, it is more intended as inspiration for other users than as a robust plotting tool.