每隔一段时间,我尝试使用canvas.print_figure
的{{1}}绘制的情节失败,matplotlib
我无法理解。提供一个最小的运行示例(特别是因为我无法真正重现它)对我来说很复杂,但我可以把这里的电话和追溯放在这里,我希望有人能指出我应该看的地方为了追查问题。
这是函数调用:
RuntimeError
其中canvas.print_figure(filename, papertype='a4', orientation='landscape',
dpi=300, format='png')
是canvas
个实例,而FigureCanvas
类似filename
。
这里是完整的追溯(我用点替换了长路径名称):
picture1110101.png
所以它看起来像是与Traceback (most recent call last):
File ".../draw.py", line 235, in plot
_plot(*args[1:], **kwargs)
File ".../draw.py", line 177, in _plot
dpi=dpi, format=ftype)
File ".../matplotlib/backend_bases.py", line 2093, in print_figure
**kwargs)
File ".../matplotlib/backends/backend_agg.py", line 491, in print_png
FigureCanvasAgg.draw(self)
File ".../matplotlib/backends/backend_agg.py", line 439, in draw
self.figure.draw(self.renderer)
File ".../matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File ".../matplotlib/figure.py", line 999, in draw
func(*args)
File ".../matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File ".../matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File ".../matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File ".../matplotlib/axis.py", line 1053, in draw
tick.draw(renderer)
File ".../matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File ".../matplotlib/axis.py", line 240, in draw
self.label1.draw(renderer)
File ".../matplotlib/artist.py", line 54, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File ".../matplotlib/text.py", line 576, in draw
self._fontproperties, angle)
File ".../matplotlib/backends/backend_agg.py", line 226, in draw_tex
Z = texmanager.get_grey(s, size, self.dpi)
File ".../matplotlib/texmanager.py", line 510, in get_grey
X = read_png(os.path.join(self.texcache, pngfile))
RuntimeError: _image_module::readpng: error reading PNG header
相关的东西。我使用TeX
,并且在包init文件的开头有以下配置行:
TeX
任何提示?
答案 0 :(得分:2)
当乳胶的png输出时 - > dvi - > png转换最终成为一个空的但现有的文件。当mpl尝试读取png以将其添加到画布并因为它不是有效的png(由于为空)而失败时,会引发错误。
作为背景,mpl通过Agg后端将乳胶插入图中的方式是(iirc):
dvipng
我会抓住异常并再试一次。