0

I am trying to plot multiple animated line plots on the same graph with a delay of 1 second between each line plot in matplotlib python.

My previous question: How to create a delay between mutiple animations on the same graph (matplotlib, python)

I have a list of lists: [[10,20,30],[40,50,60],[2,3,5],[200,300,500]]

I want to plot each element of the list of list as animated line plot on the same graph. Animation should plot the 1st list , and then plot the second list, then the third list and then the fourth list. They shouldn't be plotted simultaneously.

Thanks

Plot will look like:

1 Answer 1

1

You can make use of matplotlibs interactive mode as shown here:

import pandas as pd
import matplotlib.pyplot as plt


fig, ax = plt.subplots()

plt.ion()   # set interactive mode
plt.show()
x = np.arange(130, 190, 1)
y = 97.928 * np.exp(- np.exp(-  0.1416 * (x - 146.1)))
z = 96.9684 * np.exp(- np.exp(-0.1530 * (x - 144.4)))
y_z=[y,z]
ax.set_xlim(x[0],x[-1])
ax.set_ylim(min(y[0],z[0]),max(y[-1],z[-1]))

color=['green','red']

k=0
for i in y_z:
    for j in range(len(i)):
        line, = ax.plot(x[:j],i[:j],color=color[k])
        plt.gcf().canvas.draw()
        plt.pause(0.1)
    k=k+1

enter image description here

Sign up to request clarification or add additional context in comments.

8 Comments

Please check the image I have added, The plot should be animation, as in it should pass through the points
Thankyou . I am trying to have a continuous connected line plot
Happy to help. If you feel that the above solution helped resolve your issue, please check the green mark. The above edit will draw a continuous connected line plot.
Thank you. I tried the edit. I still do not get the continuous plot as the figure you have uploaded
I copy pasted the code. But I still get points of "*"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.