如何以这样的方式删除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)
那么有没有办法从轴中删除一行并获取内存? 这种潜在的解决方案 …
我对朱莉娅很陌生。我目前正在开发一个小程序,它需要我绘制一个点并稍后将其删除(每次只会有一个点)。我正在使用 Makie 包来可视化所有内容,但我还没有找到删除点的方法,该点是通过分散(或分散!)绘制的。代码应该如下所示:
scene = scatter([0],[0], color="blue", markersize=10)
pop!(scene.scatter) #command that removes the dot drawn by the above scatter
Run Code Online (Sandbox Code Playgroud)
我发现这个线程(Julia Plotting:删除和修改现有行)显示了一种使用 pop! 删除最后绘制的东西的方法,但此代码不会运行(如果我添加场景作为参数,我会收到错误消息scatter!(scene,...)
)。
谢谢你的帮助
我已经在 Julia 中解决了描述粒子运动的 ODE,并将坐标和各自的时间保存在一个数组中。我想用粒子沿着求解的轨迹创建一个绘图的动画 gif 图像,但要做到这一点(我提出的唯一方法)是使用 绘制粒子的位置scatter
,并擦除 的先前位置每时每刻的粒子。但是我只知道scatter!
哪个会向绘图中添加更多粒子,而不是显示粒子位置的变化。那么我怎样才能在每次迭代时擦除以前的图,或者有更聪明的方法来做到这一点?如果我想使用绘图标记更早时刻粒子的轨迹怎么办?