mercredi 2 mars 2016

Plotting to browser continuously using serve_figure

I want to see plots in progress continuously driven by the plot program using browser whenever it is connected. I searched and found serve_figure.py examples that are similar to what I need. But I cant get the following test code to work. Serve_figure.py holds up the for-loop after the first plot. At the browser only the first plot is shown. I don't need the mouse event in serve_figure.py. If there is another way to do this will be most welcome.

#!/usr/bin/env pythonnter 
import serve_figure 
import time
import numpy as np
import matplotlib
matplotlib.use('TkAgg') 
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
def animate():               
    x = np.arange(0, 2*np.pi, 0.01)
    line, = ax.plot(x, np.sin(x))
    for i in np.arange(1,200):
        line.set_ydata(np.sin(x+i/10.0))        
        fig.canvas.draw()                                
        time.sleep(1)
        serve_figure.serve_figure(fig, port=8888)
win = fig.canvas.manager.window 
fig.canvas.manager.window.after(200, animate)
plt.show()




Aucun commentaire:

Enregistrer un commentaire