@@ -2093,27 +2093,33 @@ def get_supported_filetypes_grouped(cls):
20932093 groupings [name ].sort ()
20942094 return groupings
20952095
2096- def _get_output_canvas (self , format ):
2097- """Return a canvas that is suitable for saving figures to a specified
2098- file format. If necessary, this function will switch to a registered
2099- backend that supports the format.
2096+ def _get_output_canvas (self , fmt ):
21002097 """
2101- method_name = 'print_%s' % format
2098+ Return a canvas suitable for saving figures to a specified file format.
21022099
2103- # check if this canvas supports the requested format
2104- if hasattr (self , method_name ):
2100+ If necessary, this function will switch to a registered backend that
2101+ supports the format.
2102+ """
2103+ method_name = 'print_%s' % fmt
2104+
2105+ # Return the current canvas if it supports the requested format. Note
2106+ # that we explicitly support setting print_foo to None to remove
2107+ # support for a format; this is required for PdfPages to work while the
2108+ # current backend supports pdf output (because PdfPages is tightly
2109+ # coupled with backend_pdf). This feature may be removed if PdfPages
2110+ # gets decoupled from backend_pdf.
2111+ if getattr (self , method_name , None ) is not None :
21052112 return self
21062113
2107- # check if there is a default canvas for the requested format
2108- canvas_class = get_registered_canvas_class (format )
2114+ # Return a default canvas for the requested format, if it exists.
2115+ canvas_class = get_registered_canvas_class (fmt )
21092116 if canvas_class :
21102117 return self .switch_backends (canvas_class )
21112118
2112- # else report error for unsupported format
2113- formats = sorted (self .get_supported_filetypes ())
2114- raise ValueError ('Format "%s" is not supported.\n '
2115- 'Supported formats: '
2116- '%s.' % (format , ', ' .join (formats )))
2119+ # Else report error for unsupported format.
2120+ raise ValueError (
2121+ "Format {!r} is not supported (supported formats: {})"
2122+ .format (fmt , ", " .join (sorted (self .get_supported_filetypes ()))))
21172123
21182124 def print_figure (self , filename , dpi = None , facecolor = None , edgecolor = None ,
21192125 orientation = 'portrait' , format = None , ** kwargs ):
0 commit comments