【问题标题】:Plot Markers on Curve where Value of X is known in matplotlib在 matplotlib 中已知 X 值的曲线上绘制标记
【发布时间】:2017-10-11 08:57:53
【问题描述】:

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

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

现在我想在我的曲线与这些轴线交叉的位置显示标记。我该怎么做?

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

谢谢。

p.s - 我也在图中使用了多个寄生虫轴。并不是说它真的很重要,但以防万一。

Want Markers On Curve Where AXVline Crosses

【问题讨论】:

  • scipy 有一个插值模块。用它从你的 x 值估计你的 y 值。

标签: python matplotlib markers


【解决方案1】:

您可以使用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()

【讨论】:

  • 这对已知的 y 有效吗?如果没有,你会怎么做?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-20
  • 1970-01-01
相关资源
最近更新 更多