Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Matplotlib, is there a way to know the list of available output format

According to Matplotlib documentation, matplotlib.figure.save_figtakes an optional argument format (see matplotlib.figure documentation).

This parameters takes 'one of the file extensions supported by the active backend' (as said by the official documentation).

My point is: how to know, for a specific backend, the list of supported extensions?

The list of available backends is accessible thru matplotlib.rcsetup.all_backends. These backends are available in matplotlib.backends but, I do not find a way to retrieve supported extensions.

like image 424
ohe Avatar asked Sep 30 '11 08:09

ohe


People also ask

What does PLT show () do?

plt. show() starts an event loop, looks for all currently active figure objects, and opens one or more interactive windows that display your figure or figures. The plt. show() command does a lot under the hood, as it must interact with your system's interactive graphical backend.


1 Answers

If you create a figure, you can get the available supported file format with the canvas object :

import matplotlib.pyplot as plt fig = plt.figure()  print fig.canvas.get_supported_filetypes()  >>> {    'svgz': 'Scalable Vector Graphics',     'ps': 'Postscript',     'emf': 'Enhanced Metafile',     'rgba': 'Raw RGBA bitmap',    'raw': 'Raw RGBA bitmap',    'pdf': 'Portable Document Format',     'svg': 'Scalable Vector Graphics',     'eps': 'Encapsulated Postscript',     'png': 'Portable Network Graphics'  } 

and it will list all the formats in which you can output your current object.

like image 178
Cédric Julien Avatar answered Sep 20 '22 19:09

Cédric Julien