Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8cdc0da

Browse files
committed
deprecate 'savefig.extension' rcParam in favour of 'savefig.format'
remove all mention of cairo.<format> remove unnecessary check for supported formats in get_default_filetype, rely on check in _get_print_method instead for uniformity, use get_supported_filetypes instead of directly accessing self.filetypes
1 parent b822c26 commit 8cdc0da

8 files changed

Lines changed: 26 additions & 39 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
2012-06-02 Add new Axes method and pyplot function, hist2d. - PO
22

33
2012-05-31 Remove support for 'cairo.<format>' style of backend specification.
4-
- Martin Spacek
4+
Deprecate 'cairo.format' and 'savefig.extension' rcParams and
5+
replace with 'savefig.format'. - Martin Spacek
56

67
2012-05-29 pcolormesh now obeys the passed in "edgecolor" kwarg.
78
To support this, the "shading" argument to pcolormesh now only

doc/api/api_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ For new features that were added to matplotlib, please see
1414
Changes in 1.2.x
1515
================
1616

17+
* The new rc parameter ``savefig.format`` replaces ``cairo.format`` and
18+
``savefig.extension``, and sets the default file format used by
19+
:meth:`matplotlib.figure.Figure.savefig`.
20+
1721
* In :meth:`~matplotlib.pyplot.pie` and :meth:`~matplotlib.Axes.pie`, one can
1822
now set the radius of the pie; setting the *radius* to 'None' (the default
1923
value), will result in a pie with a radius of 1 as before.

examples/tests/backend_driver.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
switch, which takes a comma-separated list, or as separate arguments,
1010
e.g.
1111
12-
python backend_driver.py agg ps cairo.png cairo.ps
12+
python backend_driver.py agg ps
1313
14-
would test the agg and ps backends, and the cairo backend with output
15-
to png and ps files. If no arguments are given, a default list of
16-
backends will be tested.
14+
would test the agg and ps backends. If no arguments are given, a
15+
default list of backends will be tested.
1716
1817
Interspersed with the backend arguments can be switches for the Python
1918
interpreter executing the tests. If entering such arguments causes an
@@ -27,7 +26,6 @@
2726
from matplotlib.cbook import Bunch, dedent
2827

2928
all_backends = list(rcsetup.all_backends) # to leave the original list alone
30-
all_backends.extend(['cairo.png', 'cairo.ps', 'cairo.pdf', 'cairo.svg'])
3129

3230
# actual physical directory for each dir
3331
dirs = dict(pylab = os.path.join('..', 'pylab_examples'),
@@ -408,8 +406,7 @@ def parse_options():
408406
help=dedent('''
409407
Run tests only for these backends; comma-separated list of
410408
one or more of: agg, ps, svg, pdf, template, cairo,
411-
cairo.png, cairo.ps, cairo.pdf, cairo.svg. Default is everything
412-
except cairo.'''))
409+
Default is everything except cairo.'''))
413410
op.add_option('--clean', action='store_true', dest='clean',
414411
help='Remove result directories, run no tests')
415412
op.add_option('-c', '--coverage', action='store_true', dest='coverage',

lib/matplotlib/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ def matplotlib_fname():
630630
'text.fontweight': 'font.weight',
631631
'text.fontsize': 'font.size',
632632
'tick.size' : 'tick.major.size',
633-
'svg.embed_char_paths' : 'svg.fonttype'
633+
'svg.embed_char_paths' : 'svg.fonttype',
634+
'savefig.extension' : 'savefig.format'
634635
}
635636

636637
_deprecated_ignore_map = {
@@ -908,13 +909,7 @@ def use(arg, warn=True):
908909
"""
909910
Set the matplotlib backend to one of the known backends.
910911
911-
The argument is case-insensitive. For the Cairo backend,
912-
the argument can have an extension to indicate the type of
913-
output. Example:
914-
915-
use('cairo.pdf')
916-
917-
will specify a default of pdf output generated by Cairo.
912+
The argument is case-insensitive.
918913
919914
.. note::
920915

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,9 @@ def _print_method(*args, **kwargs):
19221922

19231923
return _print_method
19241924

1925-
if (format not in self.filetypes or
1926-
not hasattr(self, method_name)):
1927-
formats = self.filetypes.keys()
1928-
formats.sort()
1925+
formats = self.get_supported_filetypes()
1926+
if (format not in formats or not hasattr(self, method_name)):
1927+
formats = sorted(formats)
19291928
raise ValueError(
19301929
'Format "%s" is not supported.\n'
19311930
'Supported formats: '
@@ -1965,7 +1964,6 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
19651964
*format*
19661965
when set, forcibly set the file format to save to
19671966
1968-
19691967
*bbox_inches*
19701968
Bbox in inches. Only the given portion of the figure is
19711969
saved. If 'tight', try to figure out the tight bbox of
@@ -1981,6 +1979,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
19811979
19821980
"""
19831981
if format is None:
1982+
# get format from filename, or from backend's default filetype
19841983
if cbook.is_string_like(filename):
19851984
format = os.path.splitext(filename)[1][1:]
19861985
if format is None or format == '':
@@ -2080,16 +2079,11 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20802079

20812080
def get_default_filetype(self):
20822081
"""
2083-
Get the default savefig file format as specified in
2084-
rcParams['savefig.format']. If not supported, return 'png'.
2085-
Returned string excludes period. Overridden in backends that
2086-
only support a single file type.
2082+
Get the default savefig file format as specified in rcParam
2083+
``savefig.format``. Returned string excludes period. Overridden
2084+
in backends that only support a single file type.
20872085
"""
2088-
default = rcParams['savefig.format']
2089-
if default in self.get_supported_filetypes():
2090-
return default
2091-
else:
2092-
return 'png'
2086+
return rcParams['savefig.format']
20932087

20942088
def set_window_title(self, title):
20952089
"""

lib/matplotlib/figure.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,7 @@ def savefig(self, *args, **kwargs):
11101110
If *format* is *None* and *fname* is a string, the output
11111111
format is deduced from the extension of the filename. If
11121112
the filename has no extension, the value of the rc parameter
1113-
``savefig.extension`` is used. If that value is 'auto',
1114-
the backend determines the extension.
1113+
``savefig.format`` is used.
11151114
11161115
If *fname* is not a string, remember to specify *format* to
11171116
ensure that the correct backend is used.
@@ -1163,11 +1162,6 @@ def savefig(self, *args, **kwargs):
11631162

11641163
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
11651164

1166-
extension = rcParams['savefig.extension']
1167-
if args and is_string_like(args[0]) and '.' not in os.path.splitext(args[0])[-1] and extension != 'auto':
1168-
fname = args[0] + '.' + extension
1169-
args = (fname,) + args[1:]
1170-
11711165
transparent = kwargs.pop('transparent', False)
11721166
if transparent:
11731167
kwargs.setdefault('facecolor', 'none')

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ def validate_font_properties(s):
251251
'silent', 'helpful', 'debug', 'debug-annoying',
252252
])
253253

254+
def deprecate_savefig_extension(value):
255+
warnings.warn("savefig.extension is deprecated. Use savefig.format instead.")
256+
254257
validate_savefig_format = ValidateInStrings('savefig_format',
255258
['png', 'ps', 'pdf', 'svg'],
256259
ignorecase=True)
@@ -546,7 +549,7 @@ def __call__(self, s):
546549
'savefig.facecolor' : ['w', validate_color], # facecolor; white
547550
'savefig.edgecolor' : ['w', validate_color], # edgecolor; white
548551
'savefig.orientation' : ['portrait', validate_orientation], # edgecolor; white
549-
'savefig.extension' : ['auto', str], # what to add to extensionless filenames
552+
'savefig.extension' : ['png', deprecate_savefig_extension], # what to add to extensionless filenames
550553
'savefig.format' : ['png', validate_savefig_format],
551554

552555
'tk.window_focus' : [False, validate_bool], # Maintain shell focus for TkAgg

matplotlibrc.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
347347
#savefig.dpi : 100 # figure dots per inch
348348
#savefig.facecolor : white # figure facecolor when saving
349349
#savefig.edgecolor : white # figure edgecolor when saving
350-
#savefig.extension : auto # what extension to use for savefig('foo'), or 'auto'
351350
#savefig.format : png # png, ps, pdf, svg
352351

353352
# tk backend params

0 commit comments

Comments
 (0)