@@ -2081,27 +2081,25 @@ def get_supported_filetypes_grouped(cls):
2081
2081
groupings [name ].sort ()
2082
2082
return groupings
2083
2083
2084
- def _get_output_canvas (self , format ):
2085
- """Return a canvas that is suitable for saving figures to a specified
2086
- file format. If necessary, this function will switch to a registered
2087
- backend that supports the format.
2084
+ def _get_output_canvas (self , fmt ):
2088
2085
"""
2089
- method_name = 'print_%s' % format
2086
+ Return a canvas suitable for saving figures to a specified file format.
2090
2087
2091
- # check if this canvas supports the requested format
2088
+ If necessary, this function will switch to a registered backend that
2089
+ supports the format.
2090
+ """
2091
+ method_name = 'print_%s' % fmt
2092
+ # Return the current canvas if it supports the requested format.
2092
2093
if hasattr (self , method_name ):
2093
2094
return self
2094
-
2095
- # check if there is a default canvas for the requested format
2096
- canvas_class = get_registered_canvas_class (format )
2095
+ # Return a default canvas for the requested format, if it exists.
2096
+ canvas_class = get_registered_canvas_class (fmt )
2097
2097
if canvas_class :
2098
2098
return self .switch_backends (canvas_class )
2099
-
2100
- # else report error for unsupported format
2101
- formats = sorted (self .get_supported_filetypes ())
2102
- raise ValueError ('Format "%s" is not supported.\n '
2103
- 'Supported formats: '
2104
- '%s.' % (format , ', ' .join (formats )))
2099
+ # Else report error for unsupported format.
2100
+ raise ValueError (
2101
+ "Format {!r} is not supported (supported formats: {})"
2102
+ .format (fmt , ", " .join (sorted (self .get_supported_filetypes ()))))
2105
2103
2106
2104
def print_figure (self , filename , dpi = None , facecolor = None , edgecolor = None ,
2107
2105
orientation = 'portrait' , format = None , ** kwargs ):
0 commit comments