如何檢索 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.