gpt4 book ai didi

python-2.7 - Matplotlib 溢出错误 : Allocated too many blocks

转载 作者:行者123 更新时间:2023-12-04 00:52:37 27 4
gpt4 key购买 nike

我正在绘制三组大约 20 个时间序列。每个时间序列有 180 万个点,我分别绘制它们。为了减少执行时间(因为我发现 figure() 函数非常耗时),我只打开一个图形,绘制然后清理它以用于下一个时间序列。类似的东西:

import matplotlib.pyplot as plt

fig = plt.figure() # open a figure for plotting
for v in range(nfigs):
# here I build the x and y vectors from the raw data
# and also the figname string
plt.plot(x, y, linewidth=0.3)
plt.title('a title')
plt.xlabel('x-label')
plt.ylabel('y-label')
plt.grid()
plt.draw()
plt.savefig(figname)
plt.clf()
plt.close() # close the figure after the job is done

所有的图都保存正常,除了所有数据集中的一个特别是给我以下错误(编辑文件路径以保护隐私):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "batch.py", line 142, in <module>
main(fn)
File "batch.py", line 94, in main
plt.savefig(figname+'_'+nn+'.png')
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 561, in savefig
return fig.savefig(*args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 167, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 2220, in print_figure
**kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 505, in print_png
FigureCanvasAgg.draw(self)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 451, in draw
self.figure.draw(self.renderer)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\figure.py", line 1034, in draw
func(*args)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\axes.py", line 2086, in draw
a.draw(renderer)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\lines.py", line 562, in draw
drawFunc(renderer, gc, tpath, affine.frozen())
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\lines.py", line 938, in _draw_lines
self._lineFunc(renderer, gc, path, trans)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\lines.py", line 978, in _draw_solid
renderer.draw_path(gc, path, trans)
File "~\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\backends\backend_agg.py", line 145, in draw_path
self._renderer.draw_path(gc, path, transform, rgbFace)
OverflowError: Allocated too many blocks

触发此错误的时间序列绝对没有什么特别之处,我使用简单的 show() 而不是 savefig() 对其进行了检查。它既不是第一个也不是最后一个(大约 60 个时间序列),但足以打破我的剧本。非常感谢这方面的帮助!

最佳答案

您可以尝试更改 agg.path.chunksize 的值(10000-100000) 在 matplotlibrc文件或运行时在 matplotlib.rcParams .它导致渲染器以块的形式绘制路径而不是一次绘制整个路径;但根据文档,它可能会导致工件。查看样本matplotlibrc文件位于 http://matplotlib.org/1.3.1/users/customizing.html了解更多信息。

关于python-2.7 - Matplotlib 溢出错误 : Allocated too many blocks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330475/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com