python - Matplotlib animation wasting lot of memory -



python - Matplotlib animation wasting lot of memory -

im doing animation using matplolib in pyside form. animation running, works. wasting lot of memory. i'm providing test info test code below, maybe reaches end, larger data, programme stops working. can dont waste lot of memory?

import sys matplotlib import pyplot, animation import numpy np pyside import qtcore, qtgui matplotlib.backends.backend_qt4agg import figurecanvasqtagg figurecanvas moves_data import moves_x, moves_y class form(qtgui.qwidget): moves_x = moves_x moves_y = moves_y def __init__(self): super(form, self).__init__() self.initializecomponent() self.set_animation_area() def initializecomponent(self): self.hbox = qtgui.qhboxlayout() #----------------- animation button ----------------- self.btn_anim = qtgui.qpushbutton("run animation") self.btn_anim.clicked.connect(self.start_animation) self.hbox.addwidget(self.btn_anim) #---------------------------------------------------- self.setlayout(self.hbox) self.show() def set_animation_area(self): #some layout config self.fig_anim = pyplot.figure() ax = pyplot.axes(xlim=(-0.5, 500 - 0.5), ylim=(-0.5, 500 - 0.5)) self.lines = ax.plot([], [], '-g', lw=1) self.line = self.lines[0] ax.set_xticks(np.arange(-0.5, 500 - 0.5, 10)) ax.set_yticks(np.arange(-0.5, 500 - 0.5, 10)) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.grid(true, color = 'gray', linestyle = '-') self.canvas = figurecanvas(self.fig_anim) self.canvas.setparent(self) self.hbox.addwidget(self.canvas) def init_anim(self): self.line.set_data([], []) homecoming self.line, #-------problem might here!!------- def animate(self, i): run_x = [] run_y = [] k = 0 while k <= self.aux: run_x.append(self.moves_x[k]) run_y.append(self.moves_y[k]) k += 1 self.aux += 1 self.line.set_data(run_x, run_y) homecoming self.line, #------------------------------------- def start_animation(self): self.aux = 0 self.canvas.close_event() self.anim = self.get_animation() def get_animation(self): homecoming animation.funcanimation(self.fig_anim, self.animate, init_func = self.init_anim, frames = len(moves_x), interval = 10, blit=true, repeat=false) if __name__ == '__main__': app = qtgui.qapplication(sys.argv) ex = form() sys.exit(app.exec_())

i think i'm overlapping lines, tried prepare next idea, got nothing.

data link

if move_* is sliceable, such:

def animate(self, i): run_x = self.moves_x[:i] run_y = self.moves_y[:i] self.line.set_data(run_x, run_y) homecoming self.line,

if not, then

def animate(self, i): new_x = self.moves_x[i] new_y = self.moves_y[i] run_x = np.r_[self.line.get_xdata(), new_x] run_y = np.r_[self.line.get_ydata(), new_y] self.line.set_data(run_x, run_y) homecoming self.line

python animation memory matplotlib pyside

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -