如何使用 SciPy – Python绘制 ricker 曲线?
先决条件: Mathplotlib、NumPy
Ricker 小波是一种波状振荡,其振幅从 0 开始,增加,然后减小回 0。Ricker 小波,也称为“墨西哥帽小波”。
在本文中,我们将绘制使它们可用于信号处理的 ricker 曲线。它是高斯函数的负归一化二阶导数。
Syntax: scipy.signal.ricker(points, a)
Parameter:
- points: A number of points in vector. Will be centered around 0.
- a: Width parameter of the wavelet.
Returns: An array of length points in the shape of a ricker curve.
方法:
- 导入所需的模块。
- 创建一个数组来绘制ricker 曲线的形状。
- 在中心移动一个轴。
- 显示图表。
示例 1:绘制 Ricker 曲线。
Python3
from scipy import signal
import matplotlib.pyplot as plt
point = 100
hat = signal.ricker(point, 4)
fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(1, 1, 1)
# Move left y-axis and bottim x-axis to centre,
# passing through (0,0)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
# Eliminate upper and right axes
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.grid(True)
plt.plot(hat)
plt.show()
Python3
from scipy import signal
import matplotlib.pyplot as plt
point = 100
hat = -(signal.ricker(point, 4))
fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(1, 1, 1)
# Move left y-axis and bottim x-axis to centre,
# passing through (0,0)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
# Eliminate upper and right axes
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.grid(True)
plt.plot(hat)
plt.show()
输出:
示例 2:绘图 逆 Ricker 曲线。
蟒蛇3
from scipy import signal
import matplotlib.pyplot as plt
point = 100
hat = -(signal.ricker(point, 4))
fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(1, 1, 1)
# Move left y-axis and bottim x-axis to centre,
# passing through (0,0)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
# Eliminate upper and right axes
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.grid(True)
plt.plot(hat)
plt.show()
输出: