python - Basic plotting of wavelet analysis output in matplotlib -
i discovering wavelets in practice python module pywt.
i have browsed some examples of pywt module usage, not grasp essential step: don't know how display multidimensionnal output of wavelet analysis with matplotlib, basically.
this tried, (given 1 pyplot axe ax):
import pywt data_1_dimension_series = [0,0.1,0.2,0.4,-0.1,-0.1,-0.3,-0.4,1.0,1.0,1.0,0] # indeed data_1_dimension_series longer ca, cd = pywt.dwt(data_1_dimension_series, 'haar') ax.set_xlabel('seconds') ax.set_ylabel('wavelet affinity scale factor') ax.plot(axe_wt_time, zip(ca,cd)) or
data_wt_analysis = pywt.dwt(data_1_dimension_series, 'haar') ax.plot(axe_wt_time, data_wt_analysis) both ax.plot(axe_wt_time, data_wt_analysis) , ax.plot(axe_wt_time, zip(ca,cd)) not appropriate , returns error. both throws x , y must have same first dimension
the thing data_wt_analysis contain several 1d series, 1 each wavelet scale factor. surely display many graphs there scale factors. want them in same graph.
how display such data, in 1 graph, with matplotlib ?
something colourful square below:

you should extract different 1d series array of interest, , use matplotlib in simple example
import matplotlib.pyplot plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() you wish superimpose 1d plots (or line plots). so, if have lists l1, l2, l3,
import matplotlib.pyplot plt plt.plot(l1) plt.plot(l2) plt.plot(l3) plt.show() for scalogram: used imshow(). not wavelets, same id: colormap.
i have found this sample use of imshow() wavelets, didn t try thought
from pylab import * import pywt import scipy.io.wavfile wavfile # find highest power of 2 less or equal input. def lepow2(x): return 2 ** floor(log2(x)) # make scalogram given mra tree. def scalogram(data): bottom = 0 vmin = min(map(lambda x: min(abs(x)), data)) vmax = max(map(lambda x: max(abs(x)), data)) gca().set_autoscale_on(false) row in range(0, len(data)): scale = 2.0 ** (row - len(data)) imshow( array([abs(data[row])]), interpolation = 'nearest', vmin = vmin, vmax = vmax, extent = [0, 1, bottom, bottom + scale]) bottom += scale # load signal, take first channel, limit length power of 2 simplicity. rate, signal = wavfile.read('kitten.wav') signal = signal[0:lepow2(len(signal)),0] tree = pywt.wavedec(signal, 'db5') # plotting. gray() scalogram(tree) show()
Comments
Post a Comment