Images added to an axes get added to the axes' "images" member, so you can simply remove it from there.

I've attached a modified version of your script that does this. It uses a global variable which is probably not best practice, but it should be enough to give you the idea.

Cheers,
Mike

xianthax wrote:
Hello,

First thanks for the great library, recently came across it and seems quite
useful for what i'm doing.

What i'm trying to do is create an animated specgram().  I'm feeding in
audio data from a microphone at the moment, although the ultimate use is to
chart data that will be input via the line in audio port from an FMCW radar
front end for basic visualization.

I've attached simplified code below based from one of your animation
examples that shows my problem.  Initially i get fine performance given the
timeout i've set.  After about a second or two, performance goes down hill
and progressively gets worse and memory use continues to grow as if each
call to specgram creates a new instance in memory or worse is drawing a new
instance over the old. Is there another way to call specgram to avoid this? It seems the other plot types generally give the ability to update the data
for an already created graph, i haven't seen a way to do this with specgram,
perhaps this is what i'm missing?  Ultimately i would like to get the graph
image out of specgram and append them properly to get a smoother scrolling
effect but i need to get the data out of specgram fast enough first.

thanks in advance for any pointers.

import gobject
import numpy as np
import matplotlib
import array
matplotlib.use('GTKAgg')

import matplotlib.pyplot as plt
import ossaudiodev as oss

audio = oss.open('/dev/dsp','r')

print audio.setfmt(oss.AFMT_S16_LE)
print audio.channels(1)
print audio.speed(44100)

fig = plt.figure()
ax = fig.add_subplot(111)
data = array.array('H',audio.read(5880))
img = ax.specgram(data, NFFT=1024,Fs=44100, Fc=0,noverlap=64)

def update():
    data = array.array('H',audio.read(5880))
img = plt.specgram(data, NFFT=1024,Fs=44100, Fc=0,noverlap=64) fig.canvas.draw_idle() return True gobject.timeout_add(100, update) plt.show()



--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

import gobject
import numpy as np
import matplotlib
import array
matplotlib.use('GTKAgg')

import matplotlib.pyplot as plt
import ossaudiodev as oss

audio = oss.open('/dev/dsp','r')

print audio.setfmt(oss.AFMT_S16_LE)
print audio.channels(1)
print audio.speed(44100)

fig = plt.figure()
ax = fig.add_subplot(111)
data = array.array('H',audio.read(5880))
specgram = ax.specgram(data, NFFT=1024,Fs=44100, Fc=0,noverlap=64)
last_img = specgram[-1]

def update():
    global last_img
    data = array.array('H',audio.read(5880))
    ax.images.remove(last_img)
    specgram = ax.specgram(data, NFFT=1024,Fs=44100, Fc=0,noverlap=64)
    last_img = specgram[-1]
    fig.canvas.draw_idle()
    return True

gobject.timeout_add(100, update)
plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to