matplotlib 还需要安装哪些其他库来编写 tiff 文件?

What other libraries does matplotlib need installed to write tiff files?

我正在使用 matplotlib(1.4 版)创建我需要以 .tiff 格式保存的图像。我正在使用 %matplotlib inline 后端在 IPython 笔记本(3.2 版)中绘图。通常我使用 Anaconda 发行版并且能够毫无问题地将 matplotlib 图形保存到 .tiff。但是,我正在尝试将我可以作为 conda 环境共享的最小依赖项组合在一起。目前,我正在使用:

当我运行我的代码在这个环境下,我得到一个错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-3d911065b472> in <module>()
     56 f.text(.01, .38, "B", size=14)
     57 
---> 58 savefig(f, "switch_control")

<ipython-input-6-4016f8a0f32d> in savefig(fig, name)
----> 4     fig.savefig("figures/{}.tiff".format(name), dpi=300)

/Users/mwaskom/anaconda/envs/punch/lib/python2.7/site-packages/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
   1474             self.set_frameon(frameon)
   1475 
-> 1476         self.canvas.print_figure(*args, **kwargs)
   1477 
   1478         if frameon:

/Users/mwaskom/anaconda/envs/punch/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2117 
   2118         # get canvas object and print method for format
-> 2119         canvas = self._get_output_canvas(format)
   2120         print_method = getattr(canvas, 'print_%s' % format)
   2121 

/Users/mwaskom/anaconda/envs/punch/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in _get_output_canvas(self, format)
   2059         raise ValueError('Format "%s" is not supported.\n'
   2060                          'Supported formats: '
-> 2061                          '%s.' % (format, ', '.join(formats)))
   2062 
   2063     def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',

ValueError: Format "tiff" is not supported.
Supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz.

我猜测 matplotlib 中的 .tiff 支持取决于完整 Anaconda 发行版中包含的其他库之一,但是,通过四处搜索并不清楚这可能是哪一个。

有趣的是,如果我只打开 IPython 终端并使用默认后端绘图(对我来说 Mac OSX),它就可以正常工作。所以这个问题特别与 IPython notebook 内联后端有关,尽管如上所述,在使用完整的 anaconda 发行版时它工作正常。

在这两种情况下我都这样做

import matplotlib as mpl
mpl.get_backend()

显示

'module://IPython.kernel.zmq.pylab.backend_inline'

我还需要安装什么才能获得对 .tiff 文件的支持?

显然,通过 conda 安装 PIL 可为 matplotlib 中基于 Agg 的后端启用 .tiff 支持。