0

I need to plot a progressing plot in matplotlib.

I have a list of lines that I need to plot. However, I need to show the lines one after the other.

Line 1: (0,0) - (0,1)

Line 2: (0,1) - (1,1)

Line 3: (1,1) - (2,2)

What I want is as follows:

I want the first graph to show only line 1

I want the second graph to show line 1 + line 2

I want the third graph to show line 1 + line 2 + line 3

I was only able to print 1 line at a time in a for a loop. How can I save a plot and then use it to add another line?

  • What is the expected outcome? Each frame saved as an image? The animation saved as an [ArtistAnimation](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.ArtistAnimation.html) of frames? A display of a [FuncAnimation](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.FuncAnimation.html)? – Mr. T Mar 09 '22 at 19:19

1 Answers1

0

this works:

lines = [
    [(0,0),(0,1)],
    [(0,1),(1,1)],
    [(1,2),(1,2)]
]

plt.figure(figsize=(5,3*len(lines)))

i=0
for line in lines:
    i+=1
    ax=plt.subplot(len(lines),1,i)
    for j in range(i):
        plt.plot(*lines[j])
    plt.show()

but note that in this way you are re-drowing the line in each plot