Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using matplotlib (version 1.4) to create images that I need saved in .tiff format. I am plotting in the IPython notebook (version 3.2) with the %matplotlib inline backend. Normally I use the Anaconda distribution and am able to save matplotlib figures to .tiff with no problem. However, I am trying to put together a minimal set of dependencies that I can share as a conda environment. Currently, I am using:

  • python=2.7
  • IPython-notebook
  • flask
  • numpy=1.9
  • scipy=0.16
  • pandas=0.16
  • numexpr=2.3
  • statsmodels=0.6
  • seaborn=0.6
  • matplotlib=1.4
  • scikit-learn=0.16
  • scikit-image=0.10
  • mayavi=4.3

When I run my code in this environment, I get an error:

---------------------------------------------------------------------------
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.

I am guessing that .tiff support in matplotlib depends on one of the other libraries included in the full Anaconda distribution, however, from searching around it is not clear which one this might be.

Interestingly, it works fine if I just open the IPython terminal and plot with the default backend (Mac OSX for me). So the issue is specifically related to the IPython notebook inline backend, although as stated above, that works fine when using the full anaconda distribution.

In both cases when I do

import matplotlib as mpl
mpl.get_backend()

it shows

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

What else do I need to have installed to gain support for .tiff files?

like image 885
mwaskom Avatar asked Aug 06 '15 17:08

mwaskom


People also ask

What are the 4 commonly application used by TIFF files?

TIFF is widely supported by scanning, faxing, word processing, optical character recognition, image manipulation, desktop publishing, and page-layout applications.

How do I save an image as a TIFF in Python?

Add a library reference (import the library) to your Python project. Open the source JPG file in Python. Call the 'save()' method, passing an output filename with TIFF extension. Get the result of JPG conversion as TIFF.


1 Answers

Apparently, installing PIL through conda enables .tiff support for Agg-based backends in matplotlib.

like image 106
mwaskom Avatar answered Sep 17 '22 17:09

mwaskom