我在ipython笔记本中使用以下代码将条形图另存为.png文件:
plt.savefig(filename, bbox_inches='tight')
它在我的计算机上工作,我已经尝试在另一台计算机上运行该脚本。然而,当我试图在另一台机器上运行它时,我得到了以下错误。
AssertionError
---> 119 plt.savefig(filename,bbox_inches='tight')
C:\Python27\lib\site-packages\matplotlib\pyplot.pyc in savefig(*args,**kwargs)
---> 472 self.canvas.print_figure(*args,**kwargs)
C:\Python27\lib\site-packages\matplotlib\figure.pyc in savefig(self,*args,**kwargs)
---> 1363 self.canvas.print_figure(*args,**kwargs)
C:\Python27\lib\site-packages\matplotlib\backend_bases.pyc
---> 2054 bbox_inches = self.figure.get_tightbbox(renderer)
C:\Python27\lib\site-packages\matplotlib\figure.pyc in get_tightbbox(self,renderer)
---> 1496 _bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
C:\Python27\lib\site-packages\matplotlib\transforms.pyc in union(bboxes)
---> 714 assert(len(bboxes))
AssertionError:删除bbox_inches=‘the’参数似乎可以解决错误并保存一个文件,但其中没有图片,只有一个完全空白的.png文件。
我已经确保我们的python、matplotlib和其他包的版本都是一样的。以前有没有人遇到过这个问题?我认为这可能是matplotlib中的一个bug,但那就没有意义了,因为它在我的电脑上运行得很好,而且我们有相同的版本。有什么想法或建议吗?
发布于 2013-05-10 10:46:33
以内联方式运行ipython时产生错误。
ipython.exe notebook --pylab=inline要解决此问题,只需删除'=inline‘即可。
发布于 2013-04-24 12:23:45
这通常意味着不会在画布上渲染任何图形。这也解释了为什么当你删除参数时,没有对应的图像!例如:
import pylab
pylab.savefig('test', bbox_inches='tight')产生类似的错误:
pylab.savefig('test', bbox_inches='tight')
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 471, in savefig
return fig.savefig(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1185, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1985, in print_figure
bbox_inches = self.figure.get_tightbbox(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1326, in get_tightbbox
_bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])
File "/usr/lib/pymodules/python2.7/matplotlib/transforms.py", line 675, in union
assert(len(bboxes))发布于 2014-08-12 00:05:20
我收到了完全相同的错误消息。我通过gui显示了图像,然后保存了它,这就产生了错误。我通过先保存它,然后才显示它来解决它。
https://stackoverflow.com/questions/16182936
复制相似问题