Change JPG compression ratio in savefig

Hi,

I am using matplotlib.savefig to save my figures as JPEG files.
Now I need to reduce the JPG compression ratio.
How can I do this?

Any hint is appreciated.

Frank

You can use dpi=600 as a parameter to increase the resolution but I'm not sure if that's what you mean. If you mean the actual compression strategy used like to Jpeg2000 per se. Might have to do that after saving the file with an image library (for example, PIL).

Cheers,
Jeff

···

On 09/06/2011 03:21 AM, Frank Breitling wrote:

Hi,

I am using matplotlib.savefig to save my figures as JPEG files.
Now I need to reduce the JPG compression ratio.
How can I do this?

Any hint is appreciated.

Frank

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

When you call savefig(), you can pass "quality", "optimize" and "progressive", as defined in the print_jpg docstring:

         def print_jpg(self, filename_or_obj, *args, **kwargs):
             """
             Supported kwargs:

             *quality*: The image quality, on a scale from 1 (worst) to
                 95 (best). The default is 75. Values above 95 should
                 be avoided; 100 completely disables the JPEG
                 quantization stage.

             *optimize*: If present, indicates that the encoder should
                 make an extra pass over the image in order to select
                 optimal encoder settings.

             *progressive*: If present, indicates that this image
                 should be stored as a progressive JPEG file.
             """

Mike

···

On 09/05/2011 01:21 PM, Frank Breitling wrote:

Hi,

I am using matplotlib.savefig to save my figures as JPEG files.
Now I need to reduce the JPG compression ratio.
How can I do this?

Any hint is appreciated.

Frank

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

Sorry for the noise -- I missed that this was already replied to (and with much greater detail).

Mike

···

On 09/06/2011 12:41 PM, Michael Droettboom wrote:

When you call savefig(), you can pass "quality", "optimize" and
"progressive", as defined in the print_jpg docstring:

          def print_jpg(self, filename_or_obj, *args, **kwargs):
              """
              Supported kwargs:

              *quality*: The image quality, on a scale from 1 (worst) to
                  95 (best). The default is 75. Values above 95 should
                  be avoided; 100 completely disables the JPEG
                  quantization stage.

              *optimize*: If present, indicates that the encoder should
                  make an extra pass over the image in order to select
                  optimal encoder settings.

              *progressive*: If present, indicates that this image
                  should be stored as a progressive JPEG file.
              """

Mike

On 09/05/2011 01:21 PM, Frank Breitling wrote:

Hi,

I am using matplotlib.savefig to save my figures as JPEG files.
Now I need to reduce the JPG compression ratio.
How can I do this?

Any hint is appreciated.

Frank

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA