Skip to content

Commit bffd54b

Browse files
committed
add examples/bode-plot.py
1 parent 5e2db71 commit bffd54b

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

examples/bode-plot.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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")

examples/bode-plot@2x.png

217 KB
Loading

src/physics_plot/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
def hello() -> str:
2-
return "Hello from physics-plot!"

src/physics_plot/pp_base.mplstyle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ text.usetex : True
4040
text.latex.preamble : \usepackage{amsmath} \usepackage{amssymb}
4141

4242
# Grid Color
43-
grid.color : 0.5
43+
grid.color : "0.9"
44+
45+
# Legend
46+
legend.fancybox : False
47+
legend.fontsize : small
4448

4549
# Save Fig
46-
savefig.dpi : 300
50+
savefig.dpi : 600

0 commit comments

Comments
 (0)