Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the bit-depth of figures produced using Matplotlib

I'm using matplotlib to generate some figures via savefig. These figures are black and white and need to be saved at a very high resolution (1000 dpi) in TIFF format. It would therefore be beneficial to save them with a reduced bit depth so as to use less memory.

To that end, my question: how does one specify the bit depth when saving figures with matplotlib?

Thanks!

like image 822
sircolinton Avatar asked Sep 12 '14 14:09

sircolinton


1 Answers

So far I get the impression that matplotlib doesn't support a bit-depth option. I'm thus using imagemagick to convert the image posthoc:

convert -monochrome +dither A.tiff B.tiff

Several things I'll mention in case someone else is trying to do similarly:

When I first changed the bitdepth by running convert -monochrome A.tiff B.tiff, the fonts looked unacceptably ugly (even at 1000 DPI!). This was because of antialiasing, which matplotlib performs by default. I couldn't find any option to turn this off, but its negative effects (when downsampling the DPI) can be largely circumvented by enabling dithering. Therefore, even if there is an option to change the DPI of the output image in matplotlib, it isn't useful unless it performs dithering or unless there's also an option to disable antialiasing.

Short answer, I would suggest to anyone in a similar situation as me to do their monochrome conversion posthoc as I have done.

like image 87
sircolinton Avatar answered Nov 03 '22 07:11

sircolinton