In Matplotlib, is there a way to know the list of available output format

前端 未结 3 1421
逝去的感伤
逝去的感伤 2021-01-03 18:39

According to Matplotlib documentation, matplotlib.figure.save_figtakes an optional argument format (see matplotlib.figure documentation).

T

相关标签:
3条回答
  • 2021-01-03 19:05

    The FigureCanvasBase class, located in each backends has a get_supported_filetypes method.

    For backend_agg:

    figure = matplotlib.figure.Figure()
    fcb = matplotlib.backends.backend_agg.FigureCanvasBase(figure)
    supported_file_types = fcb.get_supported_filetypes()
    

    supported_file_types contains:

    {'emf': 'Enhanced Metafile',
     'eps': 'Encapsulated Postscript',
     'pdf': 'Portable Document Format',
     'png': 'Portable Network Graphics',
     'ps': 'Postscript',
     'raw': 'Raw RGBA bitmap',
     'rgba': 'Raw RGBA bitmap',
     'svg': 'Scalable Vector Graphics',
     'svgz': 'Scalable Vector Graphics'}
    

    One remaining question .... matplotlib.get_backend() returns "agg". Is there an easier way to directly point to the correct backend module?

    0 讨论(0)
  • 2021-01-03 19:05

    Here is a list of renderers and file types: http://matplotlib.sourceforge.net/faq/installing_faq.html#what-is-a-backend Beyond that, individual backends have get_supported_filetypes method in their respective FigureCanvas{backend-name} class that gives a list of supported file formats.

    0 讨论(0)
  • 2021-01-03 19:09

    If you create a figure, you can get the available supported file format with the canvas object :

    import matplotlib.pyplot as plt
    fig = plt.figure()
    
    print fig.canvas.get_supported_filetypes()
    
    >>> {
       'svgz': 'Scalable Vector Graphics', 
       'ps': 'Postscript', 
       'emf': 'Enhanced Metafile', 
       'rgba': 'Raw RGBA bitmap',
       'raw': 'Raw RGBA bitmap',
       'pdf': 'Portable Document Format', 
       'svg': 'Scalable Vector Graphics', 
       'eps': 'Encapsulated Postscript', 
       'png': 'Portable Network Graphics' 
    }
    

    and it will list all the formats in which you can output your current object.

    0 讨论(0)
提交回复
热议问题