From 03d5c5fe4a7216cfb9316fa1da5b81e128b4ba41 Mon Sep 17 00:00:00 2001 From: Peter Sharpe Date: Tue, 30 Jan 2024 01:00:00 -0500 Subject: [PATCH] clean up plot --- ...ared_curvature_display_spectral_convergence.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/aerosandbox/numpy/integrate_discrete_derivations/discrete_squared_curvature_display_spectral_convergence.py b/aerosandbox/numpy/integrate_discrete_derivations/discrete_squared_curvature_display_spectral_convergence.py index 1b0fe6f4..4cc08659 100644 --- a/aerosandbox/numpy/integrate_discrete_derivations/discrete_squared_curvature_display_spectral_convergence.py +++ b/aerosandbox/numpy/integrate_discrete_derivations/discrete_squared_curvature_display_spectral_convergence.py @@ -14,7 +14,7 @@ print(float(exact)) def get_approx(period=10, method="cubic"): - x_vals = np.cosspace(0, 1, n_samples).astype(float) + x_vals = np.linspace(0, 1, n_samples).astype(float) f_vals = s.lambdify( x, f.subs(k, (n_samples - 1) / period), @@ -40,8 +40,8 @@ def get_approx(period=10, method="cubic"): import matplotlib.pyplot as plt import aerosandbox.tools.pretty_plots as p -fig, ax = plt.subplots(2, 1) -for method in ["cubic", "simpson", "subgradient", "hybrid_simpson_cubic"]: +fig, ax = plt.subplots(2, 1, figsize=(6, 8)) +for method in ["cubic", "simpson", "hybrid_simpson_cubic"]: approxes = np.vectorize( lambda period: get_approx(period, method=method) )(periods) @@ -51,4 +51,13 @@ def get_approx(period=10, method="cubic"): plt.xlabel("Period [samples]") ax[0].set_ylabel("Relative Error") ax[1].set_ylabel("Approximation") +plt.sca(ax[1]) +p.hline( + float(exact), + color="k", + linestyle="--", + label="Exact", + alpha=0.5 +) + p.show_plot() \ No newline at end of file