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

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

要检索matplotlib savefig() 函数支持的文件格式列表,我们可以使用 get_supported_filetypes()

步骤

  • 首先,获取当前的图表。
  • 设置包含图表的画布。
  • 使用 get_supported_filetypes() 方法。
  • 迭代文件类型项。
  • 要显示图表,请使用 show() 方法。

更多Matplotlib教程,请访问:Matplotlib教程

例子

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教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程