Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import matplotlib
- matplotlib.use('wxAgg')
- from matplotlib.figure import Figure
- import matplotlib.animation as animation
- from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
- import wx
- import numpy as np
- class Frame(wx.Frame):
- def __init__(self,*args,**kwargs):
- wx.Frame.__init__(self,*args,**kwargs)
- self.initCtrls()
- self.initAnim()
- self.Show()
- def initCtrls(self):
- self.mainsz = wx.BoxSizer(wx.VERTICAL)
- self.figure = Figure()
- self.axes = self.figure.add_subplot(111)
- self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
- self.mainsz.Add(self.canvas, 1, wx.EXPAND)
- self.SetSizer(self.mainsz)
- def initAnim(self):
- data = np.loadtxt("example.txt", delimiter=",")
- self.x = data[:,0]
- self.y = data[:,1]
- self.line1, = self.axes.plot([],[], '-')
- self.line2, = self.axes.plot([],[],'--')
- self.axes.set_xlim(np.min(self.x), np.max(self.x))
- self.axes.set_ylim(np.min(self.y), np.max(self.y))
- K = 0.75
- ani = animation.FuncAnimation(self.figure, self.animate, frames=len(self.x), fargs=(K,),
- interval=100, blit=True)
- self.canvas.draw()
- def animate(self,i,k):
- self.line1.set_xdata(self.x[:i])
- self.line1.set_ydata(self.y[:i])
- self.line2.set_xdata(self.x[:i])
- self.line2.set_ydata(k*self.y[:i])
- return self.line1, self.line2
- if __name__ == "__main__":
- app = wx.App()
- fr = Frame(None, wx.ID_ANY, "Example")
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement