Matplotlib 如何在已包含数据的绘图上绘制单点?

Matplotlib 如何在已包含数据的绘图上绘制单点?,matplotlib,Matplotlib,在while循环中,我正在更新绘图中的两组数据(一些数据X和一个阈值)。现在我想在同一个图上添加单点(X的峰值)。我该怎么做 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

在while循环中,我正在更新绘图中的两组数据(一些数据X和一个阈值)。现在我想在同一个图上添加单点(X的峰值)。我该怎么做

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()

只需使用正确样式的
plot

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()