在Matplotlib中,有没有办法知道可用输出格式的列表

ohe*_*ohe 30 python matplotlib

根据Matplotlib文档,matplotlib.figure.save_fig采用可选参数format(参见matplotlib.figure文档).

此参数采用"活动后端支持的文件扩展名之一"(如官方文档所述).

我的观点是:对于特定的后端,如何知道支持的扩展名列表?

可访问的可用后端列表可通过matplotlib.rcsetup.all_backends.这些后端可用,matplotlib.backends但我找不到检索支持的扩展的方法.

Céd*_*ien 39

如果创建图形,则可以使用canvas对象获取可用的支持文件格式:

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' 
}
Run Code Online (Sandbox Code Playgroud)

它将列出您可以输出当前对象的所有格式.