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

Skip to content

Commit 5114b14

Browse files
committed
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=/branches/v1_0_maint/; revision=8920
1 parent c5ccff9 commit 5114b14

2 files changed

Lines changed: 37 additions & 18 deletions

File tree

lib/matplotlib/axes.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6921,14 +6921,14 @@ def pcolor(self, *args, **kwargs):
69216921
69226922
%(PolyCollection)s
69236923
6924-
Note: the default *antialiaseds* is taken from
6924+
Note: the default *antialiaseds* is False if the default
6925+
*edgecolors*="none" is used. This eliminates artificial lines
6926+
at patch boundaries, and works regardless of the value of
6927+
alpha. If *edgecolors* is not "none", then the default
6928+
*antialiaseds* is taken from
69256929
rcParams['patch.antialiased'], which defaults to *True*.
6926-
In some cases, particularly if *alpha* is 1,
6927-
you may be able to reduce rendering artifacts (light or
6928-
dark patch boundaries) by setting it to *False*. An
6929-
alternative it to set *edgecolors* to 'face'. Unfortunately,
6930-
there seems to be no single combination of parameters that
6931-
eliminates artifacts under all conditions.
6930+
Stroking the edges may be preferred if *alpha* is 1, but
6931+
will cause artifacts otherwise.
69326932
69336933
"""
69346934

@@ -6977,21 +6977,28 @@ def pcolor(self, *args, **kwargs):
69776977

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

6980+
linewidths = (0.25,)
6981+
if 'linewidth' in kwargs:
6982+
kwargs['linewidths'] = kwargs.pop('linewidth')
6983+
kwargs.setdefault('linewidths', linewidths)
6984+
69806985
if shading == 'faceted':
69816986
edgecolors = 'k',
69826987
else:
69836988
edgecolors = 'none'
6984-
linewidths = (0.25,)
6985-
# Not sure if we want to have the following, or just trap
6986-
# invalid kwargs and raise an exception.
69876989
if 'edgecolor' in kwargs:
69886990
kwargs['edgecolors'] = kwargs.pop('edgecolor')
6989-
if 'linewidth' in kwargs:
6990-
kwargs['linewidths'] = kwargs.pop('linewidth')
6991+
ec = kwargs.setdefault('edgecolors', edgecolors)
6992+
6993+
# aa setting will default via collections to patch.antialiased
6994+
# unless the boundary is not stroked, in which case the
6995+
# default will be False; with unstroked boundaries, aa
6996+
# makes artifacts that are often disturbing.
69916997
if 'antialiased' in kwargs:
69926998
kwargs['antialiaseds'] = kwargs.pop('antialiased')
6993-
kwargs.setdefault('edgecolors', edgecolors)
6994-
kwargs.setdefault('linewidths', linewidths)
6999+
if 'antialiaseds' not in kwargs and ec.lower() == "none":
7000+
kwargs['antialiaseds'] = False
7001+
69957002

69967003
collection = mcoll.PolyCollection(verts, **kwargs)
69977004

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)