gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:08:23 25 4
gpt4 key购买 nike

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

此参数采用“事件后端支持的文件扩展名之一”(如官方文档所述)。

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

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

最佳答案

如果你创建一个图形,你可以通过 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'
}

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

关于python - 在 Matplotlib 中,有没有办法知道可用输出格式的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com