gpt4 book ai didi

python - 在 matplotlib 中已知 X 值的曲线上绘制标记

转载 作者:太空宇宙 更新时间:2023-11-04 00:36:16 24 4
gpt4 key购买 nike

我根据从实验中获得的数据绘制了一条 w.r.t 时间序列曲线。以 10 毫秒的间隔收集数据。数据是单行数组。

我还计算了一个数组,其中包含触发某个设备的时间。我画了这些触发位置的轴线。

现在我想在我的曲线穿过这些轴线的地方显示标记。我该怎么做?

触发时间(X-已知)。曲线画出来了,但没有任何方程(不规则的实验数据)。触发间隔也不总是相同的。

谢谢。

p.s - 我也在图上使用了多个寄生虫轴。这并不重要,只是以防万一。

Want Markers On Curve Where AXVline Crosses

最佳答案

您可以使用 numpy.interp()对数据进行插值。

import numpy as np
import matplotlib.pyplot as plt

trig = np.array([0.4,1.3,2.1])
time = np.linspace(0,3,9)
signal = np.sin(time)+1.3

fig, ax = plt.subplots()
ax.plot(time, signal)
for x in trig:
ax.axvline(x, color="limegreen")
#interpolate:
y = np.interp(trig, time, signal)
ax.plot(trig, y, ls="", marker="*", ms=15, color="crimson")

plt.show()

enter image description here

关于python - 在 matplotlib 中已知 X 值的曲线上绘制标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43930954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com