# Copyright (C) 2026 Todd Pataky
import numpy as np
def legend_manual(ax, colors=None, labels=None, linestyles=None, markerfacecolors=None, linewidths=None, **kwdargs):
n = len(colors)
if linestyles is None:
linestyles = ['-']*n
if linewidths is None:
linewidths = [1]*n
if markerfacecolors is None:
markerfacecolors = colors
x0,x1 = ax.get_xlim()
y0,y1 = ax.get_ylim()
h = [ax.plot([x1+1,x1+2,x1+3], [y1+1,y1+2,y1+3], ls, color=color, linewidth=lw, markerfacecolor=mfc)[0] for color,ls,lw,mfc in zip(colors,linestyles,linewidths,markerfacecolors)]
ax.set_xlim(x0, x1)
ax.set_ylim(y0, y1)
return ax.legend(h, labels, **kwdargs)
[docs]
def plot_errorcloud(datum, sd, ax=None, x=None, facecolor=None, edgecolor=None, alpha=0.5, autoset_ylim=True):
'''
Plot an error cloud around a datum continuum.
:Parameters:
- *datum* --- 1D list or numpy array
- *sd* --- 1D list or numpy array
- *ax* --- matplotlib.axes object
- *x* --- x positions [default: np.arange(datum.size)]
- *facecolor* --- SD cloud face color
- *edgecolor* --- SD cloud edge color
- *alpha* --- SD cloud face alpha
- *autoset_ylim* --- if True (default), set y limits to show all plotted
elements
:Returns:
- **matplotlib.collections.PatchCollection** object
:Example:
>>> import numpy as np
>>> from matplotlib import pyplot
>>> a = np.random.rand(50)
>>> b = np.random.rand(50)
>>> spm1d.plot.plot_errorcloud(a, b)
>>> pyplot.xlim(0, 50)
'''
from . _plotters import DataPlotter
plotter = DataPlotter(ax)
y,s = np.asarray(datum, dtype=float), np.asarray(sd, dtype=float)
plotter._set_x(x, y.size)
Y = np.array([y+s, y-s])
h = plotter.plot_cloud(Y, facecolor, edgecolor, alpha)
if autoset_ylim:
plotter._set_ylim()
return h