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