在 Matplotlib 中,有没有办法知道可用输出格式的列表 [英] In Matplotlib, is there a way to know the list of available output format

查看:33
本文介绍了在 Matplotlib 中,有没有办法知道可用输出格式的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Matplotlib 文档,matplotlib.figure.save_fig采用可选参数 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?

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

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.

推荐答案

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

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.

这篇关于在 Matplotlib 中,有没有办法知道可用输出格式的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆