Reputation: 37464
In a while loop I'm updating two sets of data in a plot (some data X and a threshold). Now I'd like to add single points (peaks of X) on the same plot. How can I do that?
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure()
plt_ps = fig.add_subplot(111)
# initialize plots
powerspectrum, = plt_ps.plot(np.zeros([windowSize,]))
threshold, = plt_ps.plot(np.zeros([windowSize,]))
peaks, = plt_ps.plot([], [], 'or') # peaks will just be a set of coordinates, eg peaks_x=[2,4,7] and peaks_y=[3,7,6]
while(somecondition):
# some data processing
powerspectrum.set_ydata(new_powerspectrum_data)
threshold.set_ydata(new_threshold_data)
#peaks.? how do I set new peaks? Tried peaks.set_data(peaks_x, peaks_y) but peaks do not show up
plt_ps.relim()
plt_ps.autoscale_view()
fig.canvas.draw()
Upvotes: 1
Views: 105
Reputation: 17455
Just use plot
with the right style:
import matplotlib.pyplot as plt
xs = [1,2,5,3,6,7,1,3,4,5,2,6,7,8,2,1]
ys = [3,4,5,2,7,1,3,4,1,2,3,4,5,2,3,1]
plt.plot(xs,ys,'.')
plt.show()
Upvotes: 1