相关疑难解决方法(0)

如何删除Matplotlib图中的线条

如何以这样的方式删除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)

那么有没有办法从轴中删除一行并获取内存? 这种潜在的解决方案 …

python plot matplotlib

71
推荐指数
5
解决办法
9万
查看次数

标签 统计

matplotlib ×1

plot ×1

python ×1