将matplotlib图保存到tiff时出错

时间:2016-01-29 19:06:17

标签: python matplotlib tiff

我可以使用.png格式的matplotlib成功保存图表。但是,当我尝试以.tiff格式保存时,我收到此错误:

plt.savefig(base_dir+'Plots'+os.sep+path+os.sep+title+'.tiff',  dpi=500)

错误:

  File "C:/Users/r/workspace/FLE/plots.py", line 1310, in plot_by_region
    plt.savefig(base_dir+'Plots'+os.sep+path+os.sep+title+'.tiff',  dpi=500)
  File "C:\Anaconda64\lib\site-packages\matplotlib\pyplot.py", line 688, in savefig
    res = fig.savefig(*args, **kwargs)
  File "C:\Anaconda64\lib\site-packages\matplotlib\figure.py", line 1539, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Anaconda64\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 196, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\Anaconda64\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
    **kwargs)
  File "C:\Anaconda64\lib\site-packages\matplotlib\backends\backend_agg.py", line 594, in print_tif
    dpi=dpi)
  File "C:\Anaconda64\lib\site-packages\PIL\Image.py", line 1665, in save
    save_handler(self, fp, filename)
  File "C:\Anaconda64\lib\site-packages\PIL\TiffImagePlugin.py", line 1320, in _save
    offset = ifd.save(fp)
  File "C:\Anaconda64\lib\site-packages\PIL\TiffImagePlugin.py", line 608, in save
    if len(data) <= 4:
TypeError: object of type 'int' has no len()

1 个答案:

答案 0 :(得分:1)

回滚到Pillow 2.9.0并保存到.tiff工作。见这里:https://github.com/python-pillow/Pillow/issues/1524