plot Classic List Threaded 4 messages Open this post in threaded view
|

plot

 I want help on graphI need to plot numbers one by one (lets say after interval of 5 sec) but all in the same graph. How to do ?My code is belowimport time    import matplotlib.pyplot as pltimport numpy as npfrom random import randinti = 1numbers = *5while i < 5:     numbers[i] = randint(0,100)     plt.plot(np.arange(1,6),numbers, 'o')     i += 1     matplotlib.pyplot.draw()     time.sleep(5) _______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users
Open this post in threaded view
|

Re: plot

 Try using plt.pause instead of time.sleep.  This may do what you want import matplotlib.pyplot as plt from random import randint numbers = *5 # draw the initial points oldlines = plt.plot(range(1, 6), numbers, 'o', c='r') plt.pause(5) for i in range(5):     numbers[i] = randint(0,100)     # remove the previously plotted lines before drawing the new ones     oldlines.remove()     oldlines = plt.plot(range(1, 6), numbers, 'o', c='r')     plt.pause(5) > On May 31, 2019, at 5:07 AM, Partha Sinha <[hidden email]> wrote: > > I want help on graph > I need to plot numbers one by one (lets say after interval of 5 sec) but all in the same graph. How to do ? > My code is below > > > import time     > import matplotlib.pyplot as plt > import numpy as np > from random import randint > i = 1 > numbers = *5 > while i < 5: >      numbers[i] = randint(0,100) >      plt.plot(np.arange(1,6),numbers, 'o') >      i += 1 >      matplotlib.pyplot.draw() >      time.sleep(5) > _______________________________________________ > Matplotlib-users mailing list > [hidden email] > https://mail.python.org/mailman/listinfo/matplotlib-users_______________________________________________ Matplotlib-users mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-users