Error in saving matplotlib plot to tiff

僤鯓⒐⒋嵵緔 提交于 2020-01-06 20:00:47

问题


I can successfully save a plot using matplotlib in .png format. However, when I try to save it in .tiff format, I get this error:

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

Error:

  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:


rolling back to Pillow 2.9.0 and saving to .tiff works. See here: https://github.com/python-pillow/Pillow/issues/1524



来源:https://stackoverflow.com/questions/35092163/error-in-saving-matplotlib-plot-to-tiff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!