如何以这样的方式删除matplotlib轴的一行(或多行),因为它实际上会收集垃圾并释放内存?下面的代码似乎删除了行,但从不释放内存(即使显式调用gc.collect())
from matplotlib import pyplot
import numpy
a = numpy.arange(int(1e7))
# large so you can easily see the memory footprint on the system monitor.
fig = pyplot.Figure()
ax = pyplot.add_subplot(1, 1, 1)
lines = ax.plot(a) # this uses up an additional 230 Mb of memory.
# can I get the memory back?
l = lines[0]
l.remove()
del l
del lines
# not releasing memory
ax.cla() # this does release the memory, but also wipes out all other lines.
Run Code Online (Sandbox Code Playgroud)
那么有没有办法从轴中删除一行并获取内存? 这种潜在的解决方案 …
我在这里读到matplotlib擅长处理大型数据集.我正在编写一个数据处理应用程序并将matplotlib图形嵌入到wx中,并且发现matplotlib在处理大量数据时都是可怕的,无论是速度还是内存方面.有没有人知道一种方法来加速(减少内存占用)matplotlib而不是下采样输入?
为了说明matplotlib与内存有多糟糕,请考虑以下代码:
import pylab
import numpy
a = numpy.arange(int(1e7)) # only 10,000,000 32-bit integers (~40 Mb in memory)
# watch your system memory now...
pylab.plot(a) # this uses over 230 ADDITIONAL Mb of memory
Run Code Online (Sandbox Code Playgroud) 我正在用python编写应用程序(使用wxPython作为gui),我正在寻找一种独立于平台的方法来决定存储应用程序设置文件的位置.在linux系统上,通常存储应用程序设置文件的位置是什么?在Mac和Windows(所有现代版本)上怎么样?
理想情况下,我想要一个提供平台无关接口的模块来定位这些文件.这样的事情已经存在吗?
我正在寻找一种估算信号功率的好方法(定期采样10 kHz)与时间仅一个频率(比如50 Hz).我可以计算频谱图,然后在目标频率上拍摄一片.这似乎效率低下,因为我只关心一个频率对时间的功率.我意识到正好一个频率的功率为零(在极限范围内),我想在目标频率附近的一个小频率间隔内计算信号的功率.
我目前的"解决方案"是使用Matplotlib的mlab.specgram()函数,该函数返回一个2d数组的幂,我只是将它切片.我对此并不满意,因为我并不完全信任mab.specgram()函数,因为在不同信号上计算频谱图需要非常不同的时间(即使它们的长度相同).