1

I want to do an animation with lines in matplotlib. Basically, the line is 2 points, and each point is (x,y) coordinates. Each next lines begins from the end of current line. After showing the line it disappears. The static code looks like this:

for i in range(0, len(numberOfPoints)-1):
    plt.clf()
    x1 = xPoints[i]
    x2 = XPoints[i+1]
    y1 = yPoints[i]
    y2 = yPoints[i+1]
    plt.plot([x1,x2], [y1,y2])

How can I animate it?

efri gado
  • 11
  • 1
  • 1
    Matplotlib has an extensive list of [example code and tutorials](https://matplotlib.org/stable/gallery/index.html#animation). What have you tried to implement your idea, why did it fail? – Mr. T Mar 09 '21 at 11:36
  • matplotlib has `FuncAnimation` for this and you should find many tutorials and examples (even in questions on Stackoverflow) how to use it. If you want to do it manually then you may need `thread` and some `sleep()` to slow down it because it may create it too fast and you don't see it. – furas Mar 09 '21 at 11:39
  • better create minimal working code which we could simply copy and run - it helps to test ideas and solutions. – furas Mar 09 '21 at 11:40
  • [Here is a 3D version](https://stackoverflow.com/a/65181776/8881141) of what you probably try to achieve in 2D. – Mr. T Mar 09 '21 at 11:52

0 Answers0