如何检索 Matplotlib savefig() 函数支持的文件格式列表?


若要检索 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

更新于:2021-06-17

271 浏览

开启你的职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.