Để lấy danh sách định dạng file hỗ trợ cho savefig() Matplotlib, ta dùng get_supported_filetypes().
Các bước
- Lấy figure hiện tại.
- Lấy canvas chứa figure.
- Gọi get_supported_filetypes().
- Duyệt các cặp key-value định dạng file.
- Hiển thị hình bằng show().
Ví dụ
from matplotlib import pyplot as plt
fs = plt.gcf().canvas.get_supported_filetypes()
for key, val in fs.items():
print(key, ":", val)
Kết quả
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