Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/03/2014, 21:29
santiagoyepes
 
Fecha de Ingreso: junio-2013
Mensajes: 9
Antigüedad: 10 años, 10 meses
Puntos: 0
Matplotlib animacion de grafico

Saludos

Código:
import math
import numpy
import matplotlib.pyplot

h = 0.83  
transmission_coeff = 2e-5 

latency_time = 5. # days       
infectious_time = 5. # days                     
end_time = 80.0 # days
num_steps = int(end_time / h)                                                       
times = h * numpy.array(range(num_steps + 1))  
ks=6.0  
ki=6.0   

def seir_model():

    s = numpy.zeros(num_steps + 1)                      
    e = numpy.zeros(num_steps + 1)
    i = numpy.zeros(num_steps + 1)
    r = numpy.zeros(num_steps + 1)


    s[0] = 10000 -10 -60
    e[0] = 60                      
    i[0] = 10
    r[0] = 0
                                        

    for step in range(num_steps):
    	s2e=h*transmission_coeff*ks*s[step]*i[step]
    	e2i=h*transmission_coeff*ki*s[step-infectious_time]*i[step-infectious_time]
    	i2r=h*recovery_rate*i[step]
    	r2s=h*reinfection_coeff*r[step]
    	s[step+1]=s[step]-s2e+r2s
    	e[step+1]=e[step]+s2e-e2i
    	i[step+1]=i[step]+e2i-death_coeff*i[step]-i2r
    	r[step+1]=r[step]+i2r-r2s

        return s, i, r, e


s, i, r, e = seir_model() 


s_plot = matplotlib.pyplot.plot(times, s, label = 'S')
e_plot = matplotlib.pyplot.plot(times, e, label = 'E')
i_plot = matplotlib.pyplot.plot(times, i, label = 'I')
r_plot = matplotlib.pyplot.plot(times, r, label = 'R')
matplotlib.pyplot.legend(('S', 'E', 'I', 'R'), loc = 'upper right')
    
axes = matplotlib.pyplot.gca()
axes.set_xlabel('Time in days')
axes.set_ylabel('Number of persons')
matplotlib.pyplot.xlim(xmin = 0.)
matplotlib.pyplot.ylim(ymin = 0.)
matplotlib.pyplot.show()


El problema es que me sale el grafico de una solo vez y lo que quiero es que valla graficando como si estuviera animado, ver como se van formando las curvas, hay alguna forma simple de hacer esto, agradezco la ayuda!

Agredeciendo de antemano
Santiago