如何检索 Matplotlib savefig() 函数支持的文件格式列表?
matplotlibpythondata visualization更新于 2025/7/11 1:48:17
要检索 matplotlib savefig() 函数支持的文件格式列表,我们可以使用 get_supported_filetypes()。
步骤
- 首先获取当前图形。
- 设置包含图形的画布。
- 使用 get_supported_filetypes() 方法。
- 迭代文件类型项。
- 要显示图形,请使用 show() 方法。
示例
from matplotlib import pyplot as plt fs = plt.gcf().canvas.get_supported_filetypes() for key, val in fs.items(): print(key, ":", val)
输出
eps : Encapsulated Postscript jpg : Joint Photographic Experts Group jpeg : Joint Photographic Experts Group pdf : Portable Document Format pgf : PGF code for LaTeX png : Portable Network Graphics ps : Postscript raw : Raw RGBA bitmap rgba : Raw RGBA bitmap svg : Scalable Vector Graphics svgz : Scalable Vector Graphics tif : Tagged Image File Format tiff : Tagged Image File Format
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/
打印
下一节:如何使用 Matplotlib 在 Seaborn facetgrid 条形图上添加图例? ❯❮ 上一节:使用 Matplotlib 和子图以及 ArtistAnimation 制作动画

