I am trying to make a point move on the random plots in matplotlib. Please refer to the following code.
import numpy as np
import matplotlib.pyplot as plt
from time import sleep
plt.ion()
a = np.array([[1,1],[5,5],[2,4],[7,8],[4,2],[10,11]])
b = []
for i in range(a.shape[0]/2):
b.append([a[2*i],a[2*i+1]])
b = np.array(b)
for i in b: # retain this plot
plt.plot(i[:,0],i[:,1])
for i in b:
t = np.linspace(0,1,100)
for k in t:
x = (1-k)*i[0,0]+k*i[1,0]
y = (1-k)*i[0,1]+k*i[1,1]
sleep(0.1)
# plt.gcf().clear()
plt.scatter([x],[y])
plt.draw()
When I run this code, a point is moving on the plots but it is leaving traces. But, I want a single point move without leaving traces and retain the plot I made before plotting the point. If I use clear() (I commented it in the code), it is clearing the whole plot and plotting only the point.
I tried to use FuncAnimation(), but I am finding difficulty in plotting all the other plots whose number is more than 300.
Is there any method I can use. Plase, help.
Thanks