animated axis

Dear users,
I have been working on a scope based on matplotlib to monitor acquisition
data. In order to enhance frame per seconds, I have used matplotlib's blit
capabilities and works ok. No flickering, nice and smooth. Here's how it's
done, take note that bbox is taken from the figure and not the axes object
in order to make the scale animated. The problem I have, is that the figure
is all white because of this.. just a question of esthetics :slight_smile: If bbox is
taken from the axis, the scale will never be drawn. Any suggestion?

# Set all the animated object to animated
self.ax.get_xaxis().set_animated(True)
line = Line2D(tdata,ydata,animated=True)

# Then a copy of the display
background = self.canvas.copy_from_bbox(self.fig.bbox)

# then loop over the acquisition and update
self.ax.set_xlim(tdata[-1] - self.maxt,tdata[-1]) # update axis
self.line.set_data(tdata,ydata) # update line data

self.canvas.restore_region(background) # restore background

self.ax.draw_artist(self.line[0]) # redraw line
self.ax.draw_artist(self.ax.get_xaxis()) # redraw axis
聽聽
self.canvas.blit(self.fig.bbox) # blit

http://old.nabble.com/file/p26635860/acquisition.png

路路路

--
View this message in context: http://old.nabble.com/animated-axis-tp26635860p26635860.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

avee wrote:

Dear users,
I have been working on a scope based on matplotlib to monitor acquisition
data. In order to enhance frame per seconds, I have used matplotlib's blit
capabilities and works ok. No flickering, nice and smooth. Here's how it's
done, take note that bbox is taken from the figure and not the axes object
in order to make the scale animated. The problem I have, is that the
figure is all white because of this.. just a question of esthetics :slight_smile: If
bbox is taken from the axis, the scale will never be drawn. Any
suggestion?

This worked for me:
to remove axis temporary and than to take background of the whole picture
but without ticks and labels of this axis:

self.axxaxis = self.ax.get_xaxis()

# store ticker
MJF = self.axxaxis.get_major_formatter()
MJL = self.axxaxis.get_major_locator()
#remove axis
self.axxaxis.set_major_formatter(NullFormatter())
self.axxaxis.set_major_locator(NullLocator())

self.draw()

...
take background for blit
...

# restore ticker
self.axxaxis.set_major_formatter(MJF)
self.axxaxis.set_major_locator(MJL)

路路路

--
View this message in context: http://old.nabble.com/animated-axis-tp26635860p26642470.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

andreyd wrote:

This worked for me:
to remove axis temporary and than to take background of the whole picture
but without ticks and labels of this axis:

This suggestion did not resolve the problem.

But here is the solution. I have no idea why the first version is not
working.
I changed the threading technique:
聽聽- from gobject.idle_add(run) to the fig.canvas.mpl_connect('draw_event',
start_anim)

I think it can be only that... Any ideas?

import matplotlib
matplotlib.use('GTKAgg')
from pylab import figure, show
import gobject, gtk
import time

fig = figure()
ax = fig.add_subplot(111)
ax.set_xlim(0, 30)

#fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
ax.grid() # to ensure proper background restore

ax.get_xaxis().set_animated(True)

fig.canvas.draw()

def run():
聽聽if run.background is None:
聽聽聽聽run.background = fig.canvas.copy_from_bbox(fig.bbox)
聽聽
聽聽fig.canvas.restore_region(run.background)
聽聽i = run.cnt
聽聽ax.set_xlim(0+i,30+i)
聽聽fig.draw_artist(ax.get_xaxis())
聽聽聽聽
聽聽fig.canvas.blit()
聽聽
聽聽if run.cnt == 180:
聽聽聽聽gtk.main_quit()
聽聽聽聽raise SystemExit
聽聽聽聽
聽聽run.cnt += 1
聽聽time.sleep(0.1)
聽聽return True
聽聽聽聽聽聽
def start_anim(event):
聽聽聽聽gobject.idle_add(run)
聽聽聽聽fig.canvas.mpl_disconnect(start_anim.cid)

start_anim.cid = fig.canvas.mpl_connect('draw_event', start_anim)

run.background = None
run.cnt = 0

show()

路路路

--
View this message in context: http://old.nabble.com/animated-axis-tp26635860p26678529.html
Sent from the matplotlib - users mailing list archive at Nabble.com.