Reputation: 8246
I have one huge array and I'm trying to create an animation effect. My approach is:
def initPlot(self):
if not hasattr( self, 'axes' ):
self.axes = self.figure.add_subplot( 111 )
self.axes.set_title('Monitor data', size=12)
pylab.setp(self.axes.get_xticklabels(), fontsize=8)
pylab.setp(self.axes.get_yticklabels(), fontsize=8)
self.maxy = 0
self.miny = 0
for i, pt_list in enumerate( self.point_lists ):
plot_pts = num.array( pt_list )
clr = self.clr_list[i]
self.plot_data = self.axes.plot( plot_pts, linewidth= 1.0, color=clr, )[0]
self.plot_data.set_xdata(num.arange(len(plot_pts)))
self.plot_data.set_ydata(plot_pts)
maxPlot = plot_pts.max()
minPlot = plot_pts.min()
if maxPlot > self.maxy:
self.maxy = maxPlot
if minPlot < self.miny:
self.miny = minPlot
def draw( self ):
"""Draw data."""
self.axes.set_xbound(lower=self.startPosition, upper=self.startPosition + 1000)
self.axes.set_ybound(lower=self.miny - 50, upper = self.maxy + 50)
self.canvas.draw()
def onTimerPassed(self, event):
if self.animation:
self.startPosition = self.startPosition + 10
self.draw()
Now this works fine and the animation is what I expect. However I also need to integrate an NavigationToolbar2WxAgg. Here comes my problem. When the animation is active, any zoom/ reposition etc. is automatically canceled from what I can tell by the self.canvas.draw(). So my question is how can I do the plot update that keeps the settings done by the toolbar?
regards, Bogdan
Upvotes: 2
Views: 457
Reputation: 4249
You are forcing the limits to be (startPosition, startPosition+1000) and (miny-50, miny+50) in your draw()
method. For your next frame, you'll have to infer what your limits should be based on what your limits currently are.
Say you want your xlim to increase by 1000 each frame, but retain the yscale. You could do the following:
def draw(self):
xlim = self.axes.get_xlim()
self.axes.set_xlim(xlim[0]+1000, xlim[1]+1000)
# ylim unchanged
self.canvas.draw()
Upvotes: 3