Skip to content

Commit a9b94ac

Browse files
committed
Merged revisions 8920 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8920 | efiring | 2011-01-15 15:00:37 -1000 (Sat, 15 Jan 2011) | 8 lines Change pcolor and contourf default antialiasing to False; closes 3151847. To avoid misplaced boundaries and artifacts with alpha < 1, we do not stroke the pcolor and contourf patch boundaries by default; but without that stroking, antialiasing produces boundary artifacts that tend to be visually disturbing. Therefore we sacrifice antialiasing for these patches. ........ svn path=/trunk/matplotlib/; revision=8921
1 parent b237dd9 commit a9b94ac

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

lib/matplotlib/axes.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6934,14 +6934,14 @@ def pcolor(self, *args, **kwargs):
69346934
69356935
%(PolyCollection)s
69366936
6937-
Note: the default *antialiaseds* is taken from
6937+
Note: the default *antialiaseds* is False if the default
6938+
*edgecolors*="none" is used. This eliminates artificial lines
6939+
at patch boundaries, and works regardless of the value of
6940+
alpha. If *edgecolors* is not "none", then the default
6941+
*antialiaseds* is taken from
69386942
rcParams['patch.antialiased'], which defaults to *True*.
6939-
In some cases, particularly if *alpha* is 1,
6940-
you may be able to reduce rendering artifacts (light or
6941-
dark patch boundaries) by setting it to *False*. An
6942-
alternative it to set *edgecolors* to 'face'. Unfortunately,
6943-
there seems to be no single combination of parameters that
6944-
eliminates artifacts under all conditions.
6943+
Stroking the edges may be preferred if *alpha* is 1, but
6944+
will cause artifacts otherwise.
69456945
69466946
"""
69476947

@@ -6990,21 +6990,28 @@ def pcolor(self, *args, **kwargs):
69906990

69916991
C = compress(ravelmask, ma.filled(C[0:Ny-1,0:Nx-1]).ravel())
69926992

6993+
linewidths = (0.25,)
6994+
if 'linewidth' in kwargs:
6995+
kwargs['linewidths'] = kwargs.pop('linewidth')
6996+
kwargs.setdefault('linewidths', linewidths)
6997+
69936998
if shading == 'faceted':
69946999
edgecolors = 'k',
69957000
else:
69967001
edgecolors = 'none'
6997-
linewidths = (0.25,)
6998-
# Not sure if we want to have the following, or just trap
6999-
# invalid kwargs and raise an exception.
70007002
if 'edgecolor' in kwargs:
70017003
kwargs['edgecolors'] = kwargs.pop('edgecolor')
7002-
if 'linewidth' in kwargs:
7003-
kwargs['linewidths'] = kwargs.pop('linewidth')
7004+
ec = kwargs.setdefault('edgecolors', edgecolors)
7005+
7006+
# aa setting will default via collections to patch.antialiased
7007+
# unless the boundary is not stroked, in which case the
7008+
# default will be False; with unstroked boundaries, aa
7009+
# makes artifacts that are often disturbing.
70047010
if 'antialiased' in kwargs:
70057011
kwargs['antialiaseds'] = kwargs.pop('antialiased')
7006-
kwargs.setdefault('edgecolors', edgecolors)
7007-
kwargs.setdefault('linewidths', linewidths)
7012+
if 'antialiaseds' not in kwargs and ec.lower() == "none":
7013+
kwargs['antialiaseds'] = False
7014+
70087015

70097016
collection = mcoll.PolyCollection(verts, **kwargs)
70107017

lib/matplotlib/contour.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,14 @@ def __init__(self, ax, *args, **kwargs):
662662
self.colors = kwargs.get('colors', None)
663663
norm = kwargs.get('norm', None)
664664
self.extend = kwargs.get('extend', 'neither')
665-
self.antialiased = kwargs.get('antialiased', True)
665+
self.antialiased = kwargs.get('antialiased', None)
666+
if self.antialiased is None and self.filled:
667+
self.antialiased = False # eliminate artifacts; we are not
668+
# stroking the boundaries.
669+
# The default for line contours will be taken from
670+
# the LineCollection default, which uses the
671+
# rcParams['lines.antialiased']
672+
666673
self.nchunk = kwargs.get('nchunk', 0)
667674
self.locator = kwargs.get('locator', None)
668675
if (isinstance(norm, colors.LogNorm)
@@ -734,11 +741,15 @@ def __init__(self, ax, *args, **kwargs):
734741
tlinewidths = self._process_linewidths()
735742
self.tlinewidths = tlinewidths
736743
tlinestyles = self._process_linestyles()
744+
aa = self.antialiased
745+
if aa is not None:
746+
aa = (self.antialiased,)
737747
for level, width, lstyle, segs in \
738748
zip(self.levels, tlinewidths, tlinestyles, self.allsegs):
739749
# Default zorder taken from LineCollection
740750
zorder = kwargs.get('zorder', 2)
741751
col = collections.LineCollection(segs,
752+
antialiaseds = aa,
742753
linewidths = width,
743754
linestyle = lstyle,
744755
alpha=self.alpha,
@@ -1358,6 +1369,10 @@ def _initialize_x_y(self, z):
13581369
Override axis units by specifying an instance of a
13591370
:class:`matplotlib.units.ConversionInterface`.
13601371
1372+
*antialiased*: [ True | False ]
1373+
enable antialiasing, overriding the defaults. For
1374+
filled contours, the default is True. For line contours,
1375+
it is taken from rcParams['lines.antialiased'].
13611376
13621377
contour-only keyword arguments:
13631378
@@ -1385,9 +1400,6 @@ def _initialize_x_y(self, z):
13851400
13861401
contourf-only keyword arguments:
13871402
1388-
*antialiased*: [ True | False ]
1389-
enable antialiasing
1390-
13911403
*nchunk*: [ 0 | integer ]
13921404
If 0, no subdivision of the domain. Specify a positive integer to
13931405
divide the domain into subdomains of roughly *nchunk* by *nchunk*

0 commit comments

Comments
 (0)