Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/12/2013, 01:27
edanvar
 
Fecha de Ingreso: octubre-2013
Mensajes: 59
Antigüedad: 10 años, 6 meses
Puntos: 0
Respuesta: Actualizar plot dinamicamente

Muchas gracias, he encontrado otra forma de hacerlo, de hecho he conseguido hacerla funcionar, y me llama la atencion que no se parece en nada, o muy poco a la que tu propones, que no la he probado pero voy a ello.

Esta ha sido mi solucion de momento:

Código Python:
Ver original
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from pylab import *
  4. import matplotlib.animation as animation
  5. import random
  6. import time
  7.  
  8.  
  9. fig = plt.figure(figsize=(8,6), dpi=150)
  10.  
  11.  
  12.  
  13. h=4
  14. a=1
  15. b=3
  16.  
  17.  
  18.  
  19. ylim(-2.5,10.5)
  20. xlim(-2.5,4.5)
  21. grid()
  22.  
  23. def data_gen():
  24.     i = 0
  25.     while i< 1:
  26.         R1 = random.random()
  27.         R2 = random.random()
  28.         x0 = (b - a)*R1 + a
  29.         y0 = h*R2
  30.         i = i + 1
  31.         yield x0, y0
  32.  
  33.  
  34. line, = plot([], [], linestyle='none', marker='o', color='r')
  35.  
  36.  
  37.  
  38. xdata, ydata = [], []
  39.  
  40. def run(data):
  41.     x0,y0 = data
  42.     xdata.append(x0)
  43.     ydata.append(y0)
  44.     line.set_data(xdata, ydata)
  45.     time.sleep(1)
  46.     return line,
  47.  
  48. ani = animation.FuncAnimation(fig, run, data_gen, blit=True, interval=0.5,repeat=False)
  49. plt.show()

Que te parece??

Si funciona bien, la tuya me parece mas sencilla y todo!!