Osm*_*hop 5 python plot matplotlib
我在 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:
Run Code Online (Sandbox Code Playgroud)
删除 bbox_inches='tight' 参数似乎可以解决错误并保存文件,但那里没有图片,只有一个完全空白的 .png 文件。
我已经确保我们的 python、matplotlib 和其他包的版本都是相同的。以前有人遇到过这个吗?我认为这可能是 matplotlib 中的一个错误,但这没有意义,因为它在我的计算机上运行良好,而且我们有相同的版本。有什么想法或建议吗?
内联运行 ipython 时产生该错误。
ipython.exe notebook --pylab=inline
Run Code Online (Sandbox Code Playgroud)
要解决此问题,只需删除“=inline”即可。
| 归档时间: |
|
| 查看次数: |
5446 次 |
| 最近记录: |