Debian Codegraph @

demo/plot_demo_signals.py

raw symbols SCIP
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """Plot the set of 1D demo signals available in `pywt.data.demo_signal`."""
5
6 import numpy as np
7
8 import matplotlib.pyplot as plt
9
10 import pywt
11
12 # use 'list' to get a list of all available 1d demo signals
13 signals = pywt.data.demo_signal('list')
14
15 subplots_per_fig = 5
16 signal_length = 1024
17 i_fig = 0
18 n_figures = int(np.ceil(len(signals)/subplots_per_fig))
19 for i_fig in range(n_figures):
20 # Select a subset of functions for the current plot
21 func_subset = signals[
22 i_fig * subplots_per_fig:(i_fig + 1) * subplots_per_fig]
23
24 # create a figure to hold this subset of the functions
25 fig, axes = plt.subplots(subplots_per_fig, 1)
26 axes = axes.ravel()
27 for n, signal in enumerate(func_subset):
28 if signal in ['Gabor', 'sineoneoverx']:
29 # user cannot specify a length for these two
30 x = pywt.data.demo_signal(signal)
31 else:
32 x = pywt.data.demo_signal(signal, signal_length)
33 ax = axes[n]
34 ax.plot(x.real)
35 if signal == 'Gabor':
36 # The Gabor signal is complex-valued
37 ax.plot(x.imag)
38 ax.legend(['Gabor (Re)', 'Gabor (Im)'], loc='upper left')
39 else:
40 ax.legend([signal, ], loc='upper left')
41 # omit axes for any unused subplots
42 for n in range(n + 1, len(axes)):
43 axes[n].set_axis_off()
44 plt.show()