简体   繁体   English

经过时间后删除散点图中的一个点 - matplotlib

[英]Delete a point in scatter plot after elapsed time - matplotlib

How can I delete the first point added to a plot after a certain time has elapsed?经过一段时间后,如何删除添加到图中的第一个点?

p= np.random.random()
q= np.random.random()
plt.scatter(p,q)
plt.show()

You did not provide much details, but I hope this short example helps:你没有提供太多细节,但我希望这个简短的例子有帮助:

import time
import numpy as np
import matplotlib.pyplot as plt

# create dummy data
n = 50
p, q = np.random.random((2, n))

dt = 0.1  # time interval after which one point should be removed [seconde]

h = plt.plot(p, q, ls='', marker='o')[0]

i = 0
t0 = time.time()
while i < n:
    t = time.time()
    i = int((t - t0) // dt)
    h.set_data(p[i:], q[i:])
    plt.pause(dt*0.8)  # pause the plot a little less than dt

50 个衰落点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM