MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / draw_error_band

Function draw_error_band

galleries/examples/statistics/curve_error_band.py:44–65  ·  view source on GitHub ↗
(ax, x, y, err, **kwargs)

Source from the content-addressed store, hash-verified

42
43
44def draw_error_band(ax, x, y, err, **kwargs):
45 # Calculate normals via centered finite differences (except the first point
46 # which uses a forward difference and the last point which uses a backward
47 # difference).
48 dx = np.concatenate([[x[1] - x[0]], x[2:] - x[:-2], [x[-1] - x[-2]]])
49 dy = np.concatenate([[y[1] - y[0]], y[2:] - y[:-2], [y[-1] - y[-2]]])
50 l = np.hypot(dx, dy)
51 nx = dy / l
52 ny = -dx / l
53
54 # end points of errors
55 xp = x + nx * err
56 yp = y + ny * err
57 xn = x - nx * err
58 yn = y - ny * err
59
60 vertices = np.block([[xp, xn[::-1]],
61 [yp, yn[::-1]]]).T
62 codes = np.full(len(vertices), Path.LINETO)
63 codes[0] = codes[len(xp)] = Path.MOVETO
64 path = Path(vertices, codes)
65 ax.add_patch(PathPatch(path, **kwargs))
66
67
68_, axs = plt.subplots(1, 2, layout='constrained', sharex=True, sharey=True)

Callers 1

Calls 3

PathClass · 0.90
PathPatchClass · 0.90
add_patchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…