當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Matplotlib.axes.Axes.phase_spectrum()用法及代碼示例

Matplotlib是Python中的一個庫,它是數字的-NumPy庫的數學擴展。軸類包含大多數圖形元素:Axis,Tick,Line2D,Text,Polygon等,並設置坐標係。 Axes實例通過callbacks屬性支持回調。

matplotlib.axes.Axes.phase_spectrum()函數

matplotlib庫的axiss模塊中的Axes.phase_spectrum()函數用於繪製相頻譜。

用法: Axes.phase_spectrum(self, x, Fs=None, Fc=None, window=None, pad_to=None, sides=None, *, data=None, **kwargs)


參數:此方法接受以下描述的參數:

  • x:此參數是數據序列。
  • Fs:此參數是標量。默認值為2。
  • window:此參數將數據段作為參數,並返回該段的窗口版本。其默認值為window_hanning()
  • sides:此參數指定要返回光譜的哪一側。它可以具有以下值:‘default’,‘onesided’和‘twosided’。
  • pad_to:此參數包含填充數據段的整數值。
  • Fc:此參數還包含一個整數值,用於抵消曲線圖的x範圍以反映頻率範圍。其默認值為0

返回值:這將返回以下內容:

  • spectrum:這將返回以弧度為單位的角度光譜。
  • freqs:這將返回與頻譜中的元素相對應的頻率。
  • line:這將返回此函數創建的行。

結果是(頻譜,頻率,線)

以下示例說明了matplotlib.axes中的matplotlib.axes.Axes.phase_spectrum()函數:

範例1:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
import numpy as np 
np.random.seed(10**5) 
   
  
dt = 0.0001
Fs = 1 / dt 
geeks = np.array([22.00, 61.90, 7.80, 
                  24.40, 110.25, 20.05, 
                  15.00, 22.80, 34.90, 
                  57.30]) 
  
nse = np.random.randn(len(geeks)) 
r = np.exp(-geeks / 0.05) 
   
s = 0.5 * np.sin(1.5 * np.pi * geeks) + nse 
   
# plot phase_spectrum 
fig, ax = plt.subplots() 
ax.phase_spectrum(s, Fs = Fs, color ="green") 
  
ax.set_title('matplotlib.axes.Axes.phase_spectrum()\ 
Example') 
  
plt.show()

輸出:

範例2:

# Implementation of matplotlib function 
import matplotlib.pyplot as plt 
import numpy as np 
np.random.seed(0) 
  
   
dt = 0.01
Fs = 1 / dt 
t = np.arange(0, 10, dt) 
res = np.random.randn(len(t)) 
r = np.exp(-t / 0.05) 
   
cres = np.convolve(res, r)*dt 
cres = cres[:len(t)] 
s = 0.5 * np.sin(1.5 * np.pi * t) + cres 
   
# plot simple spectrum 
fig, (ax1, ax2) = plt.subplots(2, 1) 
ax1.plot(t, s, color ="green") 
   
# plot phase_spectrum 
ax2.phase_spectrum(s, Fs = Fs, color ="green") 
   
ax1.set_title('matplotlib.axes.Axes.phase_spectrum()\ 
Example') 
  
plt.show()

輸出:





注:本文由純淨天空篩選整理自SHUBHAMSINGH10大神的英文原創作品 Matplotlib.axes.Axes.phase_spectrum() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。