当我运行栅格化示例found here并将bbox_inches='tight'
参数添加到任何savefig()
函数时,我收到以下错误。还有其他人有这个问题吗?我找不到错误报告。我使用matplotlib 1.4.0和python 2.7.6
Traceback (most recent call last):
File "raster.py", line 45, in <module>
plt.savefig("test_rasterization.pdf", dpi=150,bbox_inches='tight')
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 576, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1470, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2192, in print_figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pdf.py", line 2469, in print_pdf
self.figure.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1079, in draw
func(*args)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2092, in draw
a.draw(renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 58, in draw_wrapper
before(artist, renderer)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 43, in before
renderer.start_rasterizing()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_mixed.py", line 96, in start_rasterizing
self._bbox_inches_restore)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/tight_bbox.py", line 86, in process_figure_for_rasterizing
r = adjust_bbox(figure, bbox_inches, fixed_dpi)
NameError: global name 'figure' is not defined
答案 0 :(得分:0)
这是已修复的已知错误(https://github.com/matplotlib/matplotlib/pull/3434)(https://github.com/matplotlib/matplotlib/pull/3453)。
如果您可以编辑安装,则需要删除三个字符。您还可以下载相关代码更改的差异(https://github.com/jowr/matplotlib/commit/2191358c4d0dd2a705c418376a8a0e9e22c4ca9d.diff),可以应用补丁。