/ proof-of-concept / gong-wire
Sign in
proof-of-concept / gong-wire
gong-wire / plots.py
46 lines · 2.0 KBBlameHistoryRaw
1"""Figure from results/explore.npz (written by experiments.py). Run: python plots.py"""
3from __future__ import annotations
5import os
7import matplotlib
9matplotlib.use("Agg")
10import matplotlib.pyplot as plt # noqa: E402
11import numpy as np # noqa: E402
13HERE = os.path.dirname(os.path.abspath(__file__))
14RES = os.path.join(HERE, "results")
17def explore():
18 d = np.load(os.path.join(RES, "explore.npz"))
19 cases = [(0.0, 0.0), (4.0, 0.0), (4.0, 3.0), (4.0, 8.0)]
20 Es = (2.0, 10.0, 50.0)
21 fig, ax = plt.subplots(2, 4, figsize=(20, 8.5))
22 for j, (Kb, Hd) in enumerate(cases):
23 k = f"Kb{Kb:g}_Hd{Hd:g}_E50"
24 t, Ek, f = d[k + "_t"], d[k + "_Ek"], d[k + "_f"]
25 share = Ek / Ek.sum(1, keepdims=True)
26 ax[0, j].pcolormesh(t * 1000, f, np.log10(share.T + 1e-12), vmin=-6, vmax=0, cmap="magma", shading="auto",
27 rasterized=True)
28 ax[0, j].set(yscale="log", ylim=(f[0], f[-1]), title=f"bending {Kb:g}, dome {Hd:g}, E = 50",
29 xlabel="time (ms of sound)", ylabel="mode pitch (Hz)" if j == 0 else None)
30 for E, col in zip(Es, ("C0", "C1", "C3")):
31 k = f"Kb{Kb:g}_Hd{Hd:g}_E{E:g}"
32 t, Ek, f = d[k + "_t"], d[k + "_Ek"], d[k + "_f"]
33 share = Ek / Ek.sum(1, keepdims=True)
34 ax[1, j].plot(t * 1000, share[:, f > 4000].sum(1), color=col, label=f"E = {E:g}, above 4 kHz")
35 ax[1, j].plot(t * 1000, share[:, f > 1000].sum(1), color=col, lw=0.8, ls="--", label=f"E = {E:g}, above 1 kHz")
36 ax[1, j].set(ylim=(0, 1), xlabel="time (ms of sound)", ylabel="share of energy" if j == 0 else None)
37 ax[1, j].grid(alpha=0.3)
38 ax[1, 0].legend(fontsize=7)
39 fig.suptitle("Undamped, 64 beads, lowest mode at 100 Hz: energy share per mode (top, log color, E = 50) and above 1 / 4 kHz (bottom)")
40 fig.tight_layout()
41 fig.savefig(os.path.join(RES, "explore.png"), dpi=90)
44if __name__ == "__main__":
45 explore()
46 print("wrote results/explore.png")
↑↓ move↵openescclose