2013-05-10 34 views
2

由於python模塊pywt,我在實踐中發現了小波。matplotlib小波分析輸出的基本繪圖

我瀏覽過some examples of the pywt module usage,但我無法把握關鍵步驟:我不知道如何顯示小波分析與matplotlib的multidimensionnal輸出,基本上是這樣。

這是我試過了,(給定一個pyplot斧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 my data_1_dimension_series is much longer 

cA, cD = pywt.dwt(data_1_dimension_series, 'haar') 

ax.set_xlabel('seconds') 
ax.set_ylabel('wavelet affinity by scale factor') 

ax.plot(axe_wt_time, zip(cA,cD)) 

或也

data_wt_analysis = pywt.dwt(data_1_dimension_series, 'haar') 
ax.plot(axe_wt_time, data_wt_analysis) 

兩個ax.plot(axe_wt_time, data_wt_analysis)ax.plot(axe_wt_time, zip(cA,cD))是不恰當的,並返回錯誤。雙投x and y must have the same first dimension

事情是data_wt_analysis確實包含幾個1D系列,每個小波尺度因子一個。 我確實可以顯示與縮放因子一樣多的圖形。但我希望他們都在同一個圖表中。

我怎麼能只顯示這樣的數據,在一個圖中,與matplotlib

類似下面的豐富多彩的廣場:

enter image description here

回答

2

你應該提取你感興趣的陣列不同的1D系列,並使用matplotlib作爲最簡單的例子

import matplotlib.pyplot as plt 
plt.plot([1,2,3,4]) 
plt.ylabel('some numbers') 
plt.show() 

from doc.

你希望疊加一維圖(或線圖)。所以,如果你有列表L1,L2,L3,你會做

import matplotlib.pyplot as plt 
plt.plot(l1) 
plt.plot(l2) 
plt.plot(l3) 
plt.show() 

對於尺度圖:我使用的是imshow()。這不是用於小波,而是相同的ID:一個色彩地圖。

我發現this sample使用的imshow()與小波,奧斯卡最佳噸儘量想

from pylab import * 
import pywt 
import scipy.io.wavfile as wavfile 

# Find the highest power of two less than or equal to the input. 
def lepow2(x): 
    return 2 ** floor(log2(x)) 

# Make a scalogram given an 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) 

    for 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 the signal, take the first channel, limit length to a power of 2 for simplicity. 
rate, signal = wavfile.read('kitten.wav') 
signal = signal[0:lepow2(len(signal)),0] 
tree = pywt.wavedec(signal, 'db5') 

# Plotting. 
gray() 
scalogram(tree) 
show() 
+0

,但在這種情況下,都將具有相同的'Y = 0'起源。我要爲我想要的內容添加一張圖片。我讀過它被稱爲scalograme。 – 2013-05-10 12:35:14

+0

我已添加相應的圖像。 – 2013-05-10 12:37:52

+0

@StephaneRolland我編輯,希望這有助於 – octoback 2013-05-10 12:59:14