|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | + |
| 4 | +plt.style.use("physics_plot.pp_base") |
| 5 | + |
| 6 | + |
| 7 | +# Functions for example plot |
| 8 | +def db(x): |
| 9 | + return 20.0 * np.log10(x) |
| 10 | + |
| 11 | + |
| 12 | +def model(f): |
| 13 | + return 10.0 / (f - 1.0j * 10) |
| 14 | + |
| 15 | + |
| 16 | +# figsize=(x, y), change x and y by yourself!!! |
| 17 | +fig, (ax_m, ax_p) = plt.subplots( |
| 18 | + nrows=2, ncols=1, figsize=(5, 3.5), constrained_layout=True |
| 19 | +) |
| 20 | +fig.suptitle("Low Pass Filter") |
| 21 | +f = np.logspace(0, 3, 1000) |
| 22 | + |
| 23 | +# Magnitude |
| 24 | +ax_m.semilogx(f, db(np.abs(model(f))), "b", label="LPF") |
| 25 | +ax_m.set_xlim(1e0, 1e3) |
| 26 | +ax_m.set_ylabel("Magnitude [dB]") |
| 27 | +ax_m.grid(visible=True, which="major") |
| 28 | +ax_m.grid(visible=True, which="minor", linestyle=":") |
| 29 | +ax_m.legend(loc=1) |
| 30 | + |
| 31 | +# Phase |
| 32 | +ax_p.semilogx(f, np.angle(model(f), deg=True), "b", label="LPF") |
| 33 | +ax_p.set_xlim(1e0, 1e3) |
| 34 | +ax_p.set_ylim(0, 90) |
| 35 | +ax_p.set_xlabel("Frequency [Hz]") |
| 36 | +ax_p.set_ylabel("Phase [deg]") |
| 37 | +ax_p.grid(visible=True, which="major") |
| 38 | +ax_p.grid(visible=True, which="minor", linestyle=":") |
| 39 | +ax_p.legend(loc=1) |
| 40 | + |
| 41 | +# fig.tight_layout() |
| 42 | +fig.savefig("bode-plot@2x.png") |
0 commit comments