Friday, September 19, 2014

Find supported image formats by matplotlib package in python

While you call matplotlib.figure.savefig, you may be wondering what type of figure I can save. You can find the answer by entering some commands in python.

By checking backend engines of pyplot
import matplotlib
['GTK', 'GTKAgg', 'GTKCairo', 'FltkAgg', 'MacOSX', 'QtAgg', 'Qt4Agg', 'TkAgg', 'WX', 'WXAgg', 'CocoaAgg', 'agg', 'cairo', 'emf', 'gdk', 'pdf', 'ps', 'svg', 'template']

By checking the supported file types by canvas object
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> print fig.canvas.get_supported_filetypes()
{'svgz': 'Scalable Vector Graphics', 'tiff': 'Tagged Image File Format', 'jpg': 'Joint Photographic Experts Group', 'raw': 'Raw RGBA bitmap', 'jpeg': 'Joint Photographic Experts Group', 'png': 'Portable Network Graphics', 'ps': 'Postscript', 'emf': 'Enhanced Metafile', 'svg': 'Scalable Vector Graphics', 'eps': 'Encapsulated Postscript', 'rgba': 'Raw RGBA bitmap', 'pdf': 'Portable Document Format', 'tif': 'Tagged Image File Format'}

No comments:

Post a Comment