Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。
matplotlib.axes.Axes.specgram()函數
matplotlib庫的axiss模塊中的Axes.specgram()函數用於繪製頻譜圖。
用法: Axes.specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, window=None, noverlap=None, cmap=None, xextent=None, pad_to=None, sides=None, scale_by_freq=None, mode=None, scale=None, vmin=None, vmax=None, *, data=None, **kwargs)
參數:此方法接受以下描述的參數:
- x:此參數是數據序列。
- Fs:此參數是標量。默認值為2。
- window:此參數將數據段作為參數,並返回該段的窗口版本。其默認值為window_hanning()
- sides:此參數指定要返回光譜的哪一側。它可以具有以下值:“默認”,“單麵”和“雙麵”。
- pad_to:此參數包含填充數據段的整數值。
- Fc:此參數還包含一個整數值,用於抵消曲線圖的x範圍以反映頻率範圍。其默認值為0
- NFFT:此參數包含每個塊中用於FFT的數據點數。
- detrend:此參數包含應用於fft-ing之前的每個細分的函數,旨在刪除均值或線性趨勢{“無”,“平均值”,“線性”}。
- scale_by_freq:該參數允許對返回的頻率值進行積分。
- mode:此參數是要使用的頻譜類型,例如{'default','psd','magnitude','angle','phase'}。
- noverlap:此參數是塊之間的重疊點數。
- scale:此參數包含規範{“默認”,“線性”,“ dB”}中的值的縮放比例。
- Fc:此參數是x的中心頻率。
- camp:此參數是matplotlib.colors.Colormap實例。
返回值:這將返回以下內容:
- spectrum:這將返回以弧度為單位的角度光譜。
- freqs:這將返回與頻譜中的元素相對應的頻率。
- t:這將返回對應於段中點的時間。
- im:這將返回由imshow創建的包含光譜圖的圖像。
結果為(spectrum, freqs, t, im)
以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.specgram()函數:
示例1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
dt = 0.005
t = np.arange(0.0, 20.0, dt)
x = np.sin(np.pi * t) + 1.5 * np.cos(np.pi * t)
fig, ax1 = plt.subplots()
ax1.specgram(x, Fs = 1)
ax1.set_title('matplotlib.axes.Axes.specgram() Example')
plt.show()
輸出:
示例2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(9360801)
dt = 0.0005
t = np.arange(0.0, 20.0, dt)
s1 = np.sin(4 * np.pi * 100 * t)
s2 = 1.5 * np.sin(1.5 * np.pi * 400 * t)
s2[t <= 10] = s2[12 <= t] = 0
nse = 0.2 * np.random.random(size = len(t))
x = s1 + s2 + nse
NFFT = 512
Fs = int(1.0 / dt)
fig, ax1 = plt.subplots()
ax1.specgram(x, Fs = Fs, cmap = plt.cm.bone)
ax1.set_title('matplotlib.axes.Axes.specgram() Example')
plt.show()
輸出:
相關用法
注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.specgram() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。