我在Windows 7 64位系统上使用WinPython 64位,使用Python 3.4和matplotlib 1.5.1。我无法以tiff格式保存我的情节,例如:
import matplotlib.pyplot as plt
fig, axs = plt.subplots()
fig.savefig('mpl_tiff.tif', dpi=300)
它会说:
runfile('C:/Users/Administrator/Downloads/mpl_tiff.py', wdir='C:/Users/Administrator/Downloads')
Traceback (most recent call last):
File "<ipython-input-8-6a562331465e>", line 1, in <module>
runfile('C:/Users/Administrator/Downloads/mpl_tiff.py', wdir='C:/Users/Administrator/Downloads')
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 807, in runfile
execfile(filename, namespace)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 95, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/Administrator/Downloads/mpl_tiff.py", line 11, in <module>
fig.savefig('mpl_tiff.tif', dpi=300)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\matplotlib\figure.py", line 1565, in savefig
self.canvas.print_figure(*args, **kwargs)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 196, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\matplotlib\backend_bases.py", line 2232, in print_figure
**kwargs)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\matplotlib\backends\backend_agg.py", line 594, in print_tif
dpi=dpi)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\PIL\Image.py", line 1666, in save
save_handler(self, fp, filename)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\PIL\TiffImagePlugin.py", line 1325, in _save
offset = ifd.save(fp)
File "X:\WinPython3\python-3.4.3.amd64\lib\site-packages\PIL\TiffImagePlugin.py", line 606, in save
if len(data) <= 4:
TypeError: object of type 'int' has no len()
有人可以提供解决方案吗?谢谢!
肖恩
PS:我从谷歌上搜索这可能是问题所在:https://github.com/python-pillow/Pillow/issues/1524
但解决方案仍不明确。