(ax, x, y, err, **kwargs)
| 42 | |
| 43 | |
| 44 | def 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) |
no test coverage detected
searching dependent graphs…