Skip to content

Commit d17dbff

Browse files
committed
Merge pull request #907 from mspacek/default_filetype
replace cairo.format with savefig.format in rcParams
2 parents 7dbd4ed + bec0a4a commit d17dbff

16 files changed

+93
-122
lines changed

CHANGELOG

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
2012-06-02 Add new Axes method and pyplot function, hist2d. - PO
44

5+
2012-05-31 Remove support for 'cairo.<format>' style of backend specification.
6+
Deprecate 'cairo.format' and 'savefig.extension' rcParams and
7+
replace with 'savefig.format'. - Martin Spacek
8+
59
2012-05-29 pcolormesh now obeys the passed in "edgecolor" kwarg.
610
To support this, the "shading" argument to pcolormesh now only
711
takes "flat" or "gouraud". To achieve the old "faceted" behavior,

doc/api/api_changes.rst

+27-23
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.
@@ -237,7 +241,7 @@ Changes for 0.98.x
237241
labelsep labelspacing
238242
handlelen handlelength
239243
handlestextsep handletextpad
240-
axespad borderaxespad
244+
axespad borderaxespad
241245
================ ================
242246

243247

@@ -405,51 +409,51 @@ Old method New method
405409
------------------------------------------------------------ ------------------------------------------------------------
406410
:meth:`Bbox.height` :attr:`transforms.Bbox.height`
407411
------------------------------------------------------------ ------------------------------------------------------------
408-
`Bbox.intervalx().get_bounds()` :attr:`transforms.Bbox.intervalx`
412+
`Bbox.intervalx().get_bounds()` :attr:`transforms.Bbox.intervalx`
409413
`Bbox.intervalx().set_bounds()` [:attr:`Bbox.intervalx` is now a property.]
410414
------------------------------------------------------------ ------------------------------------------------------------
411-
`Bbox.intervaly().get_bounds()` :attr:`transforms.Bbox.intervaly`
415+
`Bbox.intervaly().get_bounds()` :attr:`transforms.Bbox.intervaly`
412416
`Bbox.intervaly().set_bounds()` [:attr:`Bbox.intervaly` is now a property.]
413417
------------------------------------------------------------ ------------------------------------------------------------
414-
:meth:`Bbox.xmin` :attr:`transforms.Bbox.x0` or
418+
:meth:`Bbox.xmin` :attr:`transforms.Bbox.x0` or
415419
:attr:`transforms.Bbox.xmin` [1]_
416420
------------------------------------------------------------ ------------------------------------------------------------
417-
:meth:`Bbox.ymin` :attr:`transforms.Bbox.y0` or
421+
:meth:`Bbox.ymin` :attr:`transforms.Bbox.y0` or
418422
:attr:`transforms.Bbox.ymin` [1]_
419423
------------------------------------------------------------ ------------------------------------------------------------
420-
:meth:`Bbox.xmax` :attr:`transforms.Bbox.x1` or
424+
:meth:`Bbox.xmax` :attr:`transforms.Bbox.x1` or
421425
:attr:`transforms.Bbox.xmax` [1]_
422426
------------------------------------------------------------ ------------------------------------------------------------
423-
:meth:`Bbox.ymax` :attr:`transforms.Bbox.y1` or
427+
:meth:`Bbox.ymax` :attr:`transforms.Bbox.y1` or
424428
:attr:`transforms.Bbox.ymax` [1]_
425429
------------------------------------------------------------ ------------------------------------------------------------
426-
`Bbox.overlaps(bboxes)` `Bbox.count_overlaps(bboxes)`
430+
`Bbox.overlaps(bboxes)` `Bbox.count_overlaps(bboxes)`
427431
------------------------------------------------------------ ------------------------------------------------------------
428-
`bbox_all(bboxes)` `Bbox.union(bboxes)`
432+
`bbox_all(bboxes)` `Bbox.union(bboxes)`
429433
[:meth:`transforms.Bbox.union` is a staticmethod.]
430434
------------------------------------------------------------ ------------------------------------------------------------
431-
`lbwh_to_bbox(l, b, w, h)` `Bbox.from_bounds(x0, y0, w, h)`
435+
`lbwh_to_bbox(l, b, w, h)` `Bbox.from_bounds(x0, y0, w, h)`
432436
[:meth:`transforms.Bbox.from_bounds` is a staticmethod.]
433437
------------------------------------------------------------ ------------------------------------------------------------
434438
`inverse_transform_bbox(trans, bbox)` `Bbox.inverse_transformed(trans)`
435439
------------------------------------------------------------ ------------------------------------------------------------
436-
`Interval.contains_open(v)` `interval_contains_open(tuple, v)`
440+
`Interval.contains_open(v)` `interval_contains_open(tuple, v)`
437441
------------------------------------------------------------ ------------------------------------------------------------
438-
`Interval.contains(v)` `interval_contains(tuple, v)`
442+
`Interval.contains(v)` `interval_contains(tuple, v)`
439443
------------------------------------------------------------ ------------------------------------------------------------
440-
`identity_transform()` :class:`matplotlib.transforms.IdentityTransform`
444+
`identity_transform()` :class:`matplotlib.transforms.IdentityTransform`
441445
------------------------------------------------------------ ------------------------------------------------------------
442446
`blend_xy_sep_transform(xtrans, ytrans)` `blended_transform_factory(xtrans, ytrans)`
443447
------------------------------------------------------------ ------------------------------------------------------------
444-
`scale_transform(xs, ys)` `Affine2D().scale(xs[, ys])`
448+
`scale_transform(xs, ys)` `Affine2D().scale(xs[, ys])`
445449
------------------------------------------------------------ ------------------------------------------------------------
446-
`get_bbox_transform(boxin, boxout)` `BboxTransform(boxin, boxout)` or
447-
`BboxTransformFrom(boxin)` or
448-
`BboxTransformTo(boxout)`
450+
`get_bbox_transform(boxin, boxout)` `BboxTransform(boxin, boxout)` or
451+
`BboxTransformFrom(boxin)` or
452+
`BboxTransformTo(boxout)`
449453
------------------------------------------------------------ ------------------------------------------------------------
450-
`Transform.seq_xy_tup(points)` `Transform.transform(points)`
454+
`Transform.seq_xy_tup(points)` `Transform.transform(points)`
451455
------------------------------------------------------------ ------------------------------------------------------------
452-
`Transform.inverse_xy_tup(points)` `Transform.inverted().transform(points)`
456+
`Transform.inverse_xy_tup(points)` `Transform.inverted().transform(points)`
453457
============================================================ ============================================================
454458

455459
.. [1] The :class:`~matplotlib.transforms.Bbox` is bound by the points
@@ -492,7 +496,7 @@ The :class:`Polar` class has moved to :mod:`matplotlib.projections.polar`.
492496
============================================================ ============================================================
493497
Old method New method
494498
============================================================ ============================================================
495-
`Artist.set_clip_path(path)` `Artist.set_clip_path(path, transform)` [5]_
499+
`Artist.set_clip_path(path)` `Artist.set_clip_path(path, transform)` [5]_
496500
============================================================ ============================================================
497501

498502
.. [5] :meth:`matplotlib.artist.Artist.set_clip_path` now accepts a
@@ -519,7 +523,7 @@ Old method New method
519523
============================================================ ============================================================
520524
Old method New method
521525
============================================================ ============================================================
522-
`ColorConvertor.to_rgba_list(c)` `ColorConvertor.to_rgba_array(c)`
526+
`ColorConvertor.to_rgba_list(c)` `ColorConvertor.to_rgba_array(c)`
523527
[:meth:`matplotlib.colors.ColorConvertor.to_rgba_array`
524528
returns an Nx4 Numpy array of RGBA color quadruples.]
525529
============================================================ ============================================================
@@ -530,7 +534,7 @@ Old method New method
530534
============================================================ ============================================================
531535
Old method New method
532536
============================================================ ============================================================
533-
`Contour._segments` :meth:`matplotlib.contour.Contour.get_paths`` [Returns a
537+
`Contour._segments` :meth:`matplotlib.contour.Contour.get_paths`` [Returns a
534538
list of :class:`matplotlib.path.Path` instances.]
535539
============================================================ ============================================================
536540

@@ -540,7 +544,7 @@ Old method New method
540544
============================================================ ============================================================
541545
Old method New method
542546
============================================================ ============================================================
543-
`Figure.dpi.get()` / `Figure.dpi.set()` :attr:`matplotlib.figure.Figure.dpi` *(a property)*
547+
`Figure.dpi.get()` / `Figure.dpi.set()` :attr:`matplotlib.figure.Figure.dpi` *(a property)*
544548
============================================================ ============================================================
545549

546550
:mod:`matplotlib.patches`

doc/pyplots/matplotlibrc

+12-13
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ backend : Agg
5959
# circles. See
6060
# http://matplotlib.sourceforge.net/matplotlib.patches.html for more
6161
# information on patch properties
62-
#patch.linewidth : 1.0 # edge width in points
63-
#patch.facecolor : blue
64-
#patch.edgecolor : black
65-
#patch.antialiased : True # render patches in antialised (no jaggies)
62+
#patch.linewidth : 1.0 # edge width in points
63+
#patch.facecolor : blue
64+
#patch.edgecolor : black
65+
#patch.antialiased : True # render patches in antialised (no jaggies)
6666

6767
### FONT
6868
#
@@ -152,11 +152,11 @@ backend : Agg
152152
#text.markup : 'plain' # Affects how text, such as titles and labels, are
153153
# interpreted by default.
154154
# 'plain': As plain, unformatted text
155-
# 'tex': As TeX-like text. Text between $'s will be
156-
# formatted as a TeX math expression.
157-
# This setting has no effect when text.usetex is True.
158-
# In that case, all text will be sent to TeX for
159-
# processing.
155+
# 'tex': As TeX-like text. Text between $'s will be
156+
# formatted as a TeX math expression.
157+
# This setting has no effect when text.usetex is True.
158+
# In that case, all text will be sent to TeX for
159+
# processing.
160160

161161
# The following settings allow you to select the fonts in math mode.
162162
# They map from a TeX font name to a fontconfig font pattern.
@@ -170,8 +170,8 @@ backend : Agg
170170
#mathtext.fontset : cm # Should be 'cm' (Computer Modern), 'stix',
171171
# 'stixsans' or 'custom'
172172
#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
173-
# fonts when a symbol can not be found in one of
174-
# the custom math fonts.
173+
# fonts when a symbol can not be found in one of
174+
# the custom math fonts.
175175

176176
### AXES
177177
# default face and edge color, default tick sizes,
@@ -266,8 +266,7 @@ figure.figsize : 6, 4 # figure size in inches
266266
#savefig.dpi : 100 # figure dots per inch
267267
#savefig.facecolor : white # figure facecolor when saving
268268
#savefig.edgecolor : white # figure edgecolor when saving
269-
270-
#cairo.format : png # png, ps, pdf, svg
269+
#savefig.format : png # png, ps, pdf, svg
271270

272271
# tk backend params
273272
#tk.window_focus : False # Maintain shell focus for TkAgg

examples/tests/backend_driver.py

+4-7
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

+5-17
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ def byte2str(b): return b
144144

145145
from matplotlib.rcsetup import (defaultParams,
146146
validate_backend,
147-
validate_toolbar,
148-
validate_cairo_format)
147+
validate_toolbar)
149148

150149
major, minor1, minor2, s, tmp = sys.version_info
151150
_python24 = (major == 2 and minor1 >= 4) or major >= 3
@@ -631,7 +630,8 @@ def matplotlib_fname():
631630
'text.fontweight': 'font.weight',
632631
'text.fontsize': 'font.size',
633632
'tick.size' : 'tick.major.size',
634-
'svg.embed_char_paths' : 'svg.fonttype'
633+
'svg.embed_char_paths' : 'svg.fonttype',
634+
'savefig.extension' : 'savefig.format'
635635
}
636636

637637
_deprecated_ignore_map = {
@@ -909,13 +909,7 @@ def use(arg, warn=True):
909909
"""
910910
Set the matplotlib backend to one of the known backends.
911911
912-
The argument is case-insensitive. For the Cairo backend,
913-
the argument can have an extension to indicate the type of
914-
output. Example:
915-
916-
use('cairo.pdf')
917-
918-
will specify a default of pdf output generated by Cairo.
912+
The argument is case-insensitive.
919913
920914
.. note::
921915
@@ -940,13 +934,7 @@ def use(arg, warn=True):
940934
else:
941935
# Lowercase only non-module backend names (modules are case-sensitive)
942936
arg = arg.lower()
943-
be_parts = arg.split('.')
944-
name = validate_backend(be_parts[0])
945-
if len(be_parts) > 1:
946-
if name == 'cairo':
947-
rcParams['cairo.format'] = validate_cairo_format(be_parts[1])
948-
else:
949-
raise ValueError('Only cairo backend has a format option')
937+
name = validate_backend(arg)
950938
rcParams['backend'] = name
951939

952940
def get_backend():

lib/matplotlib/backend_bases.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -1897,9 +1897,14 @@ def print_tif(self, filename_or_obj, *args, **kwargs):
18971897
print_tiff = print_tif
18981898

18991899
def get_supported_filetypes(self):
1900+
"""Return dict of savefig file formats supported by this backend"""
19001901
return self.filetypes
19011902

19021903
def get_supported_filetypes_grouped(self):
1904+
"""Return a dict of savefig file formats supported by this backend,
1905+
where the keys are a file type name, such as 'Joint Photographic
1906+
Experts Group', and the values are a list of filename extensions used
1907+
for that filetype, such as ['jpg', 'jpeg']."""
19031908
groupings = {}
19041909
for ext, name in self.filetypes.iteritems():
19051910
groupings.setdefault(name, []).append(ext)
@@ -1921,10 +1926,9 @@ def _print_method(*args, **kwargs):
19211926

19221927
return _print_method
19231928

1924-
if (format not in self.filetypes or
1925-
not hasattr(self, method_name)):
1926-
formats = self.filetypes.keys()
1927-
formats.sort()
1929+
formats = self.get_supported_filetypes()
1930+
if (format not in formats or not hasattr(self, method_name)):
1931+
formats = sorted(formats)
19281932
raise ValueError(
19291933
'Format "%s" is not supported.\n'
19301934
'Supported formats: '
@@ -1964,7 +1968,6 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
19641968
*format*
19651969
when set, forcibly set the file format to save to
19661970
1967-
19681971
*bbox_inches*
19691972
Bbox in inches. Only the given portion of the figure is
19701973
saved. If 'tight', try to figure out the tight bbox of
@@ -1980,6 +1983,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
19801983
19811984
"""
19821985
if format is None:
1986+
# get format from filename, or from backend's default filetype
19831987
if cbook.is_string_like(filename):
19841988
format = os.path.splitext(filename)[1][1:]
19851989
if format is None or format == '':
@@ -2078,7 +2082,12 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20782082

20792083

20802084
def get_default_filetype(self):
2081-
raise NotImplementedError
2085+
"""
2086+
Get the default savefig file format as specified in rcParam
2087+
``savefig.format``. Returned string excludes period. Overridden
2088+
in backends that only support a single file type.
2089+
"""
2090+
return rcParams['savefig.format']
20822091

20832092
def set_window_title(self, title):
20842093
"""

lib/matplotlib/backends/backend_agg.py

-3
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ def buffer_rgba(self):
463463
'debug-annoying')
464464
return self.renderer.buffer_rgba()
465465

466-
def get_default_filetype(self):
467-
return 'png'
468-
469466
def print_raw(self, filename_or_obj, *args, **kwargs):
470467
FigureCanvasAgg.draw(self)
471468
renderer = self.get_renderer()

0 commit comments

Comments
 (0)