• First get the current figure.
  • Set the canvas th">

    How to retrieve the list of supported file formats for Matplotlib savefig()function?



    To retrieve the list of supported file formats for matplotlib savefig() function, we can use get_supported_filetypes().

    Steps

    • First get the current figure.
    • Set the canvas that contains the figure.
    • Use get_supported_filetypes() method.
    • Iterate the file type items.
    • To display the figure, use show() method.

    Example

    from matplotlib import pyplot as plt
    
    fs = plt.gcf().canvas.get_supported_filetypes()
    
    for key, val in fs.items():
    print(key, ":", val)

    Output

    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
    Kickstart Your Career

    Get certified by completing the course

    Get Started
    Advertisements