[Matplotlib-users] plot

Scott Lasley selasley at icloud.com
Fri May 31 11:40:53 EDT 2019


Try using plt.pause instead of time.sleep.  This may do what you want

import matplotlib.pyplot as plt
from random import randint

numbers = [0]*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[0].remove()
    oldlines = plt.plot(range(1, 6), numbers, 'o', c='r')
    plt.pause(5)



> On May 31, 2019, at 5:07 AM, Partha Sinha <pnsinha68 at gmail.com> 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 = [0]*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
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users



More information about the Matplotlib-users mailing list