Htike Aung Kyaw
Htike Aung Kyaw

Reputation: 21

Plot Markers on Curve where Value of X is known in matplotlib

I plotted a curve w.r.t time-series from the data which I got from an experiment. Data is collected at 10ms interval. Data is single row array.

I also have calculated an array which contains the time at which a certain device is triggered. I drew axvlines of these triggered locations.

Now I want to show markers where my curve crosses these axvlines. How can I do it?

Time of trigger (X- is known). Curve is drawn but don't have any equation (irregular experiment data). Trigger interval is also not always the same.

Thanks.

p.s - I also use multiple parasite axes on figure too. Not that it really matters but just in case.

Want Markers On Curve Where AXVline Crosses

Upvotes: 2

Views: 2168

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339755

You can use numpy.interp() to interpolate the data.

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

Upvotes: 4

Related Questions