- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Jupyter Lab 中使用 matplotlib 为高斯调制波脉冲制作动画,但我无法让它工作。我希望脉冲及时向前移动,即从中间向右移动(换句话说,显示脉冲传播)。
我使用 scipy 的“signal.gausspulse”函数创建脉冲本身,该函数创建脉冲的静态图像。然后,我创建了一个 meshgrid 并尝试将脉冲“映射”到它上面,同时通过将帧编号“i”作为输入的动画函数对其进行循环,并循环遍历我们想要设置动画的值。
在我得到动画中的脉动之前,它只是静止的,没有任何运动。我认为这是因为带有波脉冲 y 值的整个数组没有随时间变化,所以我尝试创建一个循环来更新它。这有帮助,但它非常慢并且使脉搏向上移动两次,然后完全停止运动。
我无法弄清楚,真的不知道该怎么做,所以非常感谢任何帮助! :) 我可能误用了一些术语,所以我提前为此道歉 - 我试着评论代码并解释我经历的步骤,希望它能有所帮助。
%matplotlib widget
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
#setting up the canvas
fig, ax = plt.subplots(figsize=(5, 3))
ax.set(xlim=(-3, 3), ylim=(-1, 1))
#creating meshgrid for future animation
x = np.linspace(-10, 5, 200)
t = np.linspace(-10, 5, 200)
X2, T2 = np.meshgrid(x, t) #X2 and T2 are numpy arrays now
#creating the gaussian modulated pulse: fc is frequency and bw is another parameter than can be ignored
F = signal.gausspulse(X2, fc=5, bw = 0.3, retquad=False, retenv=True)[0]
#updating the values in F array to make the wave pulse move in time
j = 0
i = 0
for i in range(len(t)):
for j in range(len(t)):
F[i,j] += i - 5e-40 #some arbitrary value added/subtracted, chose e-40 bec of values in array F
#F[i,j] += j + 5e-40
#creting a Line.2D to be plotted later; F vs time
line = ax.plot(t, F[0, :], color='k', lw=2)[0]
#animating function
def animate(i):
return line.set_ydata(F[i,:])
anim = FuncAnimation(fig, animate, interval=1000, frames=1000, repeat = False)
plt.draw()
plt.grid(True)
plt.show()
最佳答案
您可以定义一个固定的 x_fixed
轴来绘制数据。然后计算一个新轴 x
,通过在每次迭代中减去 i/10
,它在每次迭代中向右平移。这个值是任意的,它决定了向右移动的速度。然后您计算平移轴上的新信号,但是您绘制相对于固定轴的信号。
使用 ax.cla()
清理之前的绘图并在每次迭代时设置网格和轴限制非常重要。
不需要网格或 for 循环。
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
x_fixed = np.linspace(-3, 3, 200)
def animate(i):
ax.cla()
x = np.linspace(-3, 3, 200) - i/10
F = signal.gausspulse(x, fc = 5, bw = 0.3, retquad = False, retenv = True)[0]
ax.plot(x_fixed, F)
ax.set(xlim = (-3, 3), ylim = (-1, 1))
ax.grid()
fig, ax = plt.subplots(figsize=(5, 3))
anim = FuncAnimation(fig, animate, interval=1000, frames=1000, repeat = False)
plt.show()
关于python - 使用 matplotlib 动画波脉冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68806579/
如果之前已经回答过这个问题,我深表歉意,但我无法找到我想要的东西。 我有一个 Box2D 动态主体,我对其应用线性脉冲以将其变成射弹。因此,当我单击屏幕上的任意位置时,我希望 body 投影到触摸位置
脉冲神经网络和循环神经网络都可以对时变信息进行建模。但我不确定哪种模型相对于计算成本更好。使用更复杂的脉冲神经网络是否值得,或者循环神经网络是否可以在所需计算量少得多的情况下工作?脉冲网络收敛得更快吗
如何在我的应用程序运行且屏幕打开时使 LED 或轨迹球闪烁或闪烁?比如接到电话时? 谢谢 最佳答案 Android 具有仅在屏幕关闭时 LED 才会亮起的硬编码功能。这是在源代码 Notificati
我的目标是从健身手环获取数据(脉搏)Torntisc T1使用我的应用程序并独立处理来自手环的数据。 为了实现,我使用了 Xamarin 并找到了一个 Bluetooth LE plugin for
我很难理解 Wait()、Pulse()、PulseAll()。他们都能避免僵局吗?如果您解释一下如何使用它们,我将不胜感激? 最佳答案 简短版: lock(obj) {...} 是 Monitor.
我在 Cigarette Smoker Problem 工作. 我只应该使用 Monitor 类。没有信号/信号量。 (是的,这是给学校的,但不是家庭作业,只是我的实践测试的免费练习,我真的需要做好准
我想使用 bcm2835.h 和纯 C 语言通过 PWM 控制 LED 二极管。我的代码不起作用。我错过了什么? 我尝试过“gpio”控制台命令,它工作正常,所以我知道 LED 已连接到正确的端口。我
在 ARKit/SceneKit 中,当用户点击按钮时,我想对我的节点施加一个脉冲。我希望冲动来自当前用户的角度。这意味着节点将远离用户的视角。多亏了这段代码,我能够获得当前的方向/方向: func
我正试图在 SK/SWIFT 中“脉冲”一个 Sprite 。我尝试使用 For 循环和 .setScale 进行粗略尝试,但它们不起作用(没有错误 - 只是没有动画)。我觉得使用 SKActions
我想为以下绘图符号设置动画(脉冲、发光)。实现所需行为的最佳方法是什么。谢谢 最佳答案 您不能为绘图符号设置动画。您可以做的是在突出显示的点上放置一个绘图空间注释。创建一个自定义的 CPTLayer
在 Perl 下,在 Linux 上将 Serial::Device 作为文件打开会重置我的 Arduino,但我不希望它被重置。 Arduino 可以通过脉冲 DTR 来重置,因此默认打开串口设备必
我用 alsa 成功渲染了音频,但是我完全无法确定 channel 映射。正如各种消息来源所说,我调用 snd_pcm_get_chmap设置好硬件和软件参数并准备好设备后。 snd_config_g
我是一名优秀的程序员,十分优秀!