Debian Codegraph @

doc/source/pyplots/plot_2d_bases.py

raw symbols SCIP
1 from itertools import product
2 import numpy as np
3 from matplotlib import pyplot as plt
4 from pywt._doc_utils import (wavedec_keys, wavedec2_keys, draw_2d_wp_basis,
5 draw_2d_fswavedecn_basis)
6
7 shape = (512, 512)
8
9 max_lev = 4 # how many levels of decomposition to draw
10 label_levels = 2 # how many levels to explicitly label on the plots
11
12 if False:
13 fig, axes = plt.subplots(1, 4, figsize=[16, 4])
14 axes = axes.ravel()
15 else:
16 fig, axes = plt.subplots(2, 2, figsize=[8, 8])
17 axes = axes.ravel()
18
19 # plot a 5-level standard DWT basis
20 draw_2d_wp_basis(shape, wavedec2_keys(max_lev), ax=axes[0],
21 label_levels=label_levels)
22 axes[0].set_title('wavedec2 ({} level)'.format(max_lev))
23
24 # plot for the fully separable case
25 draw_2d_fswavedecn_basis(shape, max_lev, ax=axes[1], label_levels=label_levels)
26 axes[1].set_title('fswavedecn ({} level)'.format(max_lev))
27
28 # get all keys corresponding to a full wavelet packet decomposition
29 wp_keys = list(product(['a', 'd', 'h', 'v'], repeat=max_lev))
30 draw_2d_wp_basis(shape, wp_keys, ax=axes[2])
31 axes[2].set_title('wavelet packet\n(full: {} level)'.format(max_lev))
32
33 # plot an example of a custom wavelet packet basis
34 keys = ['aaaa', 'aaad', 'aaah', 'aaav', 'aad', 'aah', 'aava', 'aavd',
35 'aavh', 'aavv', 'ad', 'ah', 'ava', 'avd', 'avh', 'avv', 'd', 'h',
36 'vaa', 'vad', 'vah', 'vav', 'vd', 'vh', 'vv']
37 draw_2d_wp_basis(shape, keys, ax=axes[3], label_levels=label_levels)
38 axes[3].set_title('wavelet packet\n(custom)'.format(max_lev))
39
40 plt.tight_layout()
41 plt.show()