MCPcopy Create free account
hub / github.com/PyWavelets/pywt / boundary_mode_subplot

Function boundary_mode_subplot

pywt/_doc_utils.py:154–187  ·  view source on GitHub ↗

Plot an illustration of the boundary mode in a subplot axis.

(x, mode, ax, symw=True)

Source from the content-addressed store, hash-verified

152
153
154def boundary_mode_subplot(x, mode, ax, symw=True):
155 """Plot an illustration of the boundary mode in a subplot axis."""
156
157 # if odd-length, periodization replicates the last sample to make it even
158 if mode == 'periodization' and len(x) % 2 == 1:
159 x = np.concatenate((x, (x[-1], )))
160
161 npad = 2 * len(x)
162 t = np.arange(len(x) + 2 * npad)
163 xp = pad(x, (npad, npad), mode=mode)
164
165 ax.plot(t, xp, 'k.')
166 ax.set_title(mode)
167
168 # plot the original signal in red
169 if mode == 'periodization':
170 ax.plot(t[npad:npad + len(x) - 1], x[:-1], 'r.')
171 else:
172 ax.plot(t[npad:npad + len(x)], x, 'r.')
173
174 # add vertical bars indicating points of symmetry or boundary extension
175 o2 = np.ones(2)
176 left = npad
177 if symw:
178 step = len(x) - 1
179 rng = range(-2, 4)
180 else:
181 left -= 0.5
182 step = len(x)
183 rng = range(-2, 4)
184 if mode in ['smooth', 'constant', 'zero']:
185 rng = range(2)
186 for rep in rng:
187 ax.plot((left + rep * step) * o2, [xp.min() - .5, xp.max() + .5], 'k-')

Callers 1

Calls 1

padFunction · 0.85

Tested by

no test coverage detected