|
1 | 1 | """ |
2 | 2 | ======================== |
3 | | -Spectrum Representations |
| 3 | +Spectrum representations |
4 | 4 | ======================== |
5 | 5 |
|
6 | 6 | The plots show different spectrum representations of a sine signal with |
|
24 | 24 |
|
25 | 25 | s = 0.1 * np.sin(4 * np.pi * t) + cnse # the signal |
26 | 26 |
|
27 | | -fig, axs = plt.subplots(nrows=3, ncols=2, figsize=(7, 7)) |
| 27 | +fig = plt.figure(figsize=(7, 7), layout='constrained') |
| 28 | +axs = fig.subplot_mosaic([["signal", "signal"], |
| 29 | + ["magnitude", "log_magnitude"], |
| 30 | + ["phase", "angle"]]) |
28 | 31 |
|
29 | 32 | # plot time signal: |
30 | | -axs[0, 0].set_title("Signal") |
31 | | -axs[0, 0].plot(t, s, color='C0') |
32 | | -axs[0, 0].set_xlabel("Time") |
33 | | -axs[0, 0].set_ylabel("Amplitude") |
| 33 | +axs["signal"].set_title("Signal") |
| 34 | +axs["signal"].plot(t, s, color='C0') |
| 35 | +axs["signal"].set_xlabel("Time (s)") |
| 36 | +axs["signal"].set_ylabel("Amplitude") |
34 | 37 |
|
35 | 38 | # plot different spectrum types: |
36 | | -axs[1, 0].set_title("Magnitude Spectrum") |
37 | | -axs[1, 0].magnitude_spectrum(s, Fs=Fs, color='C1') |
| 39 | +axs["magnitude"].set_title("Magnitude Spectrum") |
| 40 | +axs["magnitude"].magnitude_spectrum(s, Fs=Fs, color='C1') |
38 | 41 |
|
39 | | -axs[1, 1].set_title("Log. Magnitude Spectrum") |
40 | | -axs[1, 1].magnitude_spectrum(s, Fs=Fs, scale='dB', color='C1') |
| 42 | +axs["log_magnitude"].set_title("Log. Magnitude Spectrum") |
| 43 | +axs["log_magnitude"].magnitude_spectrum(s, Fs=Fs, scale='dB', color='C1') |
41 | 44 |
|
42 | | -axs[2, 0].set_title("Phase Spectrum ") |
43 | | -axs[2, 0].phase_spectrum(s, Fs=Fs, color='C2') |
| 45 | +axs["phase"].set_title("Phase Spectrum ") |
| 46 | +axs["phase"].phase_spectrum(s, Fs=Fs, color='C2') |
44 | 47 |
|
45 | | -axs[2, 1].set_title("Angle Spectrum") |
46 | | -axs[2, 1].angle_spectrum(s, Fs=Fs, color='C2') |
| 48 | +axs["angle"].set_title("Angle Spectrum") |
| 49 | +axs["angle"].angle_spectrum(s, Fs=Fs, color='C2') |
47 | 50 |
|
48 | | -axs[0, 1].remove() # don't display empty ax |
49 | | - |
50 | | -fig.tight_layout() |
51 | 51 | plt.show() |
0 commit comments