1

Is there a way to make it so plots made on matplotlib will cycle like a movie? If I have 12 different plots and having it show the first for 10 seconds, then the next and so on, then repeating after the last one? I would like to do this as an alternative to subplots due to the number of plots I want to show.

1

1 Answer 1

3

yes, Using animation module with repeat = True and by modifying the interval argument to control the time between plots.

import matplotlib.animation as animation

fig = plt.figure()#


data_, = plot([], [])


def data_gen():
    while i < NUMBER_OF_PLOTS:
        '''
         make your instance of X data in a list called YOUR_X_DATA
         and your Y data in a list called YOUR_Y_DATA
         and iterate along it.
        '''
        yield YOUR_X_DATA[i], YOUR_Y_DATA[i]
        i+=1

def run(data):                
    data_.set_data(data[0], data[1])

ani = animation.FuncAnimation(fig , run, data_gen, interval=100,repeat=True)
plt.show()

OR using time.sleep(10) and plt.close(fig) this way

import time 

# suppose you have fig1, fi2, fig 3 etc. 

while(True):

   time.sleep(10)
   plt.close(fig1)

   # import the next plot
   time.sleep(10)
   plt.close(fig2)


   # import the next plot

   time.sleep(10)
   plt.close(fig3)
Sign up to request clarification or add additional context in comments.

8 Comments

This should work. Would it be possible to make it so it changes everytime someone clicks a mouse or presses space?
you mean ""go to the next graph" by "change"?
I'm also still a little confused on your first example. Where do I put the different plots I want to be shown?
@greenthumbtack take alook to the comment I added. sorry
So YOUR_X_DATA is a list of lists of my data for the different plots?
|

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.