Skip to content

Instantly share code, notes, and snippets.

@reox
Created March 17, 2022 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reox/eef624d1cbaa3aca5b7443c9cb8807b9 to your computer and use it in GitHub Desktop.
Save reox/eef624d1cbaa3aca5b7443c9cb8807b9 to your computer and use it in GitHub Desktop.
Save a figure as tiff with lzw compression
import matplotlib.pyplot as plt
# do plotting:
#plt.dosomething(...)
# pil_kwargs can be used to pass things to PIL.
# the save function has **params which then passes the kwargs to the file format save function, for example:
# See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving-tiff-images
# LZW compression is called tiff_lzw in pil...
plt.savefig('foobaz.tiff', pad_inches=0.05, bbox_inches='tight', pil_kwargs=dict(compression='tiff_lzw'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment