开发者

Reusing module references in Python (Matplotlib)

开发者 https://www.devze.com 2022-12-21 09:09 出处:网络
I think I may have misunderstood something here... But here goes. I\'m using the psd method in matplotlib inside a loop, I\'m not making it plot anything, I just want the numerical result, so:

I think I may have misunderstood something here... But here goes.

I'm using the psd method in matplotlib inside a loop, I'm not making it plot anything, I just want the numerical result, so:

import pylab as pyl
...
psdResults = pyl.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)

But that's being looped 36 times every time I run the function it's in.

I'm getting a slow memory leak when I run my program over time, so used 'heapy' to monitor this, and every time I run the function, it adds 36 to these 3 heaps:

dict matplotlib.line.Line26
dict matplotlib.transforms.CompositeAffine2D
dict matplotlib.path.Path

I can only conclude that each time I use the psd method it merely adds it to some dictionary somewhere, whereas I want to effectively wipe the memory - i.e. reset pylab each loop so it doesn't store anything.

I could be misinterpreting heapy but it seems pretty clear that pylab is just growing each loop even though I only want to use it's psd m开发者_开发知识库ethod, I don't want it saving the results anywhere itself !

Cheers


Try this:

from matplotlib import mlab
psdResults = mlab.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)

Does that improve the situation?

0

精彩评论

暂无评论...
验证码 换一张
取 消