python 画大量子图报错: MemoryError: In RendererAgg: Out of memory

2018-9月5日更新

好吧,并没有解决,虽然保存成功,但是我最后一个子图毁了,解决了再来更新。。。。。

嗯~~解决方法就是我把32位的python给卸载了,装了64位的,我在sublime中跑python程序,pip来安装相关的包,安装很顺利,很多包也准备了64位python的版本,所以就换成64位没毛病!

———————————————————————分割线——————————————————————————————

2018-9月3日

我在画图时,由于要画逐小时的地图,所以有些子图非常多的情况,其中有一张图中画了39张子图,在保存图片这一行plt.savefig(savefig_path) 报错:MemoryError: In RendererAgg: Out of memory

之前内存4G,新电脑内存是32G,还是一样会报错,查了一下,一种说法是:python是32位进程,32位进程的内存地址空间是4GB,其中只有2GB给用户进程使用,另外的2GB内核保留。改用64位Python能缓解这个问题。(好吧,我不是真的懂这段说了什么意思,总之不是你内存太小,python的问题,你可以改进你的代码,释放内存来解决之)

为此重装python很麻烦,而且64bit的python也有很多不好的地方,最后参考了这个,问题得以解决,即在循环之后可加入这样一行代码,以清除当前ax对象:

plt.cla()

在官方文档中有这样一段:

You can clear the current figure with clf() and the current axes with cla(). If you find this statefulness, annoying, don’t despair, this is just a thin stateful wrapper around an object oriented API, which you can use instead (see Artist tutorial)

If you are making a long sequence of figures, you need to be aware of one more thing: the memory required for a figure is not completely released until the figure is explicitly closed with close(). Deleting all references to the figure, and/or using the window manager to kill the window in which the figure appears on the screen, is not enough, because pyplot maintains internal references until close() is called.

 

你可能感兴趣的:(Python,memoryerror,python,32bit,matplotlib)