Matplotlib OverflowError:分配了太多的块 [英] Matplotlib OverflowError: Allocated too many blocks

查看:156
本文介绍了Matplotlib OverflowError:分配了太多的块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制三组大约20个时间序列.每个时间序列都有180万个点,我分别绘制它们.为了减少执行时间(因为我发现fig()函数非常耗时),我只打开一个图形,绘制然后清理下一个时间序列.像这样:

I am plotting three sets of roughly 20 time series. Each time series has 1.8 million points and I am plotting them separately. In order to reduce execution time (because I found out that the figure() function is quite time consuming), I open one figure only, plot and then clean it for the next time series. Something like:

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

所有图都被保存了,除了特别是所有数据集中的一个图之外,这给了我以下错误(为保护隐私而编辑了文件路径):

All the plots are saved ok except for one in particular in all the data sets which gives me the following error (edited the file paths for privacy):

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个时间序列中),但是足以破坏我的脚本.非常感谢您的帮助!

The time series that triggers this error has absolutely nothing special about it, I have checked it with a simple show() instead of savefig(). It is neither the first one nor the last one (in roughly 60 time series) but it is enough to break my script. Help on this is much appreciated!

推荐答案

您可以尝试在matplotlibrc文件中或在运行时在matplotlib.rcParams中更改agg.path.chunksize(10000-100000)的值.它使渲染器以块而不是整个路径的形式绘制路径.但是根据文档,这可能会导致伪像.请参阅 http://matplotlib.org/1.3.1/users/customizing.html 了解更多信息.

You can try to change the value of agg.path.chunksize (10000-100000) in the matplotlibrc file or during run time in matplotlib.rcParams. It causes the renderer to plot paths in chunks rather than the whole path at once; but according to the docs it might cause artifacts. See the sample matplotlibrc file at http://matplotlib.org/1.3.1/users/customizing.html for some more information.

这篇关于Matplotlib OverflowError:分配了太多的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆