[Matplotlib-announce] Saving image in .jpeg format

The matplotlib-announce list is for announcements about releases of matplotlib and related projects only. Please ask user questions on matplotlib-users. (I have forwarded this message there).

There is a table of which output formats are supported by each backend here:

http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/FILETYPES?revision=3801&view=markup

GtkAgg should be your best bet, but due to its reliance on Gtk, it can't be run on a headless server. If you need to run in such a mode (such as on a webserver), your best bet is probably to use Agg, save to png, and use PIL or ImageMagick etc. to convert afterward.

Mike

Emanuele Passera wrote:

···

Hi all,
I have always used .png format for my matplotlib applications but now i am compelled to save many figures in .jpeg format.
Those image should be automatically saved (no GUI) but i can't find out how to save the images.

Executing this scripts

import pylab as p
p.rcParams['backend']='gdk'
p.figure(1)
p.plot([1,2,3,4,5,6],[3,7,5,4,6,3])
p.savefig("example.jpg")

It gives me this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/matplotlib/pyplot.py", line 345, in savefig
    return fig.savefig(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line 990, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/matplotlib/backend_bases.py", line 1373, in print_figure
    '%s.' % (format, ', '.join(formats)))
ValueError: Format "jpg" is not supported.
Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz.

Can anyone help me ? (.jpeg extension it doesn't work too)
By the way, what is the best backend to fulfill the task ? (better quality and less memory leackage ?)
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

You may want to reevaluate *why* you need jpeg. We have intentionally
not provided a jpg output because png is so much better for graphs and
text. If all you are doing is image processing of natural scenes,
then yes jpeg is better in most cases, but if you are making graphs
which is the bread and butter of matplotlib, then png will be
superior.

JDH

···

On Thu, Jan 15, 2009 at 7:56 AM, Michael Droettboom <mdroe@...86...> wrote:

The matplotlib-announce list is for announcements about releases of
matplotlib and related projects only. Please ask user questions on
matplotlib-users. (I have forwarded this message there).

There is a table of which output formats are supported by each backend here:

http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/FILETYPES?revision=3801&view=markup

GtkAgg should be your best bet, but due to its reliance on Gtk, it can't
be run on a headless server. If you need to run in such a mode (such as
on a webserver), your best bet is probably to use Agg, save to png, and
use PIL or ImageMagick etc. to convert afterward.