Source code for spm1d.plot._desc


# Copyright (C) 2026  Todd Pataky

import numpy as np


from . import _style


[docs] def plot_mean_sd(Y, ax=None, x=None, lw=3, linecolor=None, linestyle='-', facecolor=None, edgecolor=None, alpha=0.5, label=None, autoset_ylim=True, roi=None): ''' Plot mean continuum with standard deviation cloud. :Parameters: - *Y* --- (J,Q) numpy array - *ax* --- matplotlib.axes object [default: matplotlib.pyplot.gca()] - *x* --- x positions [default: np.arange(Y.shape[1])] - *lw* --- line width - *linecolor* --- mean continuum line color - *linestyle* --- mean continuum line style - *facecolor* --- SD cloud face color - *edgecolor* --- SD cloud edge color - *alpha* --- SD cloud face alpha - *label* --- mean continuum label (for matplotlib.pyplot.legend()) - *autoset_ylim* --- if True (default), set y limits to show all plotted elements - *roi* --- (Q,) boolean region-of-interest vector (mean and SD plotted only where True) :Returns: - ``(line, cloud)`` --- mean line and SD cloud :Example: Mean and standard-deviation clouds of two conditions of the plantar arch angle dataset. >>> import spm1d >>> import jikudata as jd >>> from matplotlib import pyplot as plt >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> ax = plt.gca() >>> line0, cloud0 = spm1d.plot.plot_mean_sd( y0, ax=ax, label='condition 0' ) >>> line1, cloud1 = spm1d.plot.plot_mean_sd( y1, ax=ax, linecolor='r', facecolor='r', label='condition 1' ) >>> legend = ax.legend() >>> plt.show() The example datasets require the jiku-data package: ``pip install "spm1d[data]"``. ''' from . _plotters import DataPlotter plotter = DataPlotter(ax) Y = np.asarray(Y, dtype=float) plotter._set_x(x, Y.shape[1]) Y = Y if roi is None else np.ma.masked_array( Y, np.vstack([np.logical_not(roi)]*Y.shape[0]) ) m,s = Y.mean(axis=0), Y.std(ddof=1, axis=0) h = plotter.plot(m, color=_style.ink(linecolor), lw=lw, linestyle=linestyle)[0] if label is not None: h.set_label(label) Y = np.array([m+s, m-s]) hc = plotter.plot_cloud(Y, facecolor, edgecolor, alpha) if autoset_ylim: plotter._set_axlim() return h,hc