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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.