From: <ef...@us...> - 2011-01-16 01:00:43
|
Revision: 8920 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8920&view=rev Author: efiring Date: 2011-01-16 01:00:37 +0000 (Sun, 16 Jan 2011) Log Message: ----------- 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. Modified Paths: -------------- branches/v1_0_maint/lib/matplotlib/axes.py branches/v1_0_maint/lib/matplotlib/contour.py Modified: branches/v1_0_maint/lib/matplotlib/axes.py =================================================================== --- branches/v1_0_maint/lib/matplotlib/axes.py 2011-01-15 19:49:09 UTC (rev 8919) +++ branches/v1_0_maint/lib/matplotlib/axes.py 2011-01-16 01:00:37 UTC (rev 8920) @@ -6921,14 +6921,14 @@ %(PolyCollection)s - Note: the default *antialiaseds* is taken from + Note: the default *antialiaseds* is False if the default + *edgecolors*="none" is used. This eliminates artificial lines + at patch boundaries, and works regardless of the value of + alpha. If *edgecolors* is not "none", then the default + *antialiaseds* is taken from rcParams['patch.antialiased'], which defaults to *True*. - In some cases, particularly if *alpha* is 1, - you may be able to reduce rendering artifacts (light or - dark patch boundaries) by setting it to *False*. An - alternative it to set *edgecolors* to 'face'. Unfortunately, - there seems to be no single combination of parameters that - eliminates artifacts under all conditions. + Stroking the edges may be preferred if *alpha* is 1, but + will cause artifacts otherwise. """ @@ -6977,22 +6977,29 @@ C = compress(ravelmask, ma.filled(C[0:Ny-1,0:Nx-1]).ravel()) + linewidths = (0.25,) + if 'linewidth' in kwargs: + kwargs['linewidths'] = kwargs.pop('linewidth') + kwargs.setdefault('linewidths', linewidths) + if shading == 'faceted': edgecolors = 'k', else: edgecolors = 'none' - linewidths = (0.25,) - # Not sure if we want to have the following, or just trap - # invalid kwargs and raise an exception. if 'edgecolor' in kwargs: kwargs['edgecolors'] = kwargs.pop('edgecolor') - if 'linewidth' in kwargs: - kwargs['linewidths'] = kwargs.pop('linewidth') + ec = kwargs.setdefault('edgecolors', edgecolors) + + # aa setting will default via collections to patch.antialiased + # unless the boundary is not stroked, in which case the + # default will be False; with unstroked boundaries, aa + # makes artifacts that are often disturbing. if 'antialiased' in kwargs: kwargs['antialiaseds'] = kwargs.pop('antialiased') - kwargs.setdefault('edgecolors', edgecolors) - kwargs.setdefault('linewidths', linewidths) + if 'antialiaseds' not in kwargs and ec.lower() == "none": + kwargs['antialiaseds'] = False + collection = mcoll.PolyCollection(verts, **kwargs) collection.set_alpha(alpha) Modified: branches/v1_0_maint/lib/matplotlib/contour.py =================================================================== --- branches/v1_0_maint/lib/matplotlib/contour.py 2011-01-15 19:49:09 UTC (rev 8919) +++ branches/v1_0_maint/lib/matplotlib/contour.py 2011-01-16 01:00:37 UTC (rev 8920) @@ -662,7 +662,14 @@ self.colors = kwargs.get('colors', None) norm = kwargs.get('norm', None) self.extend = kwargs.get('extend', 'neither') - self.antialiased = kwargs.get('antialiased', True) + self.antialiased = kwargs.get('antialiased', None) + if self.antialiased is None and self.filled: + self.antialiased = False # eliminate artifacts; we are not + # stroking the boundaries. + # The default for line contours will be taken from + # the LineCollection default, which uses the + # rcParams['lines.antialiased'] + self.nchunk = kwargs.get('nchunk', 0) self.locator = kwargs.get('locator', None) if (isinstance(norm, colors.LogNorm) @@ -734,11 +741,15 @@ tlinewidths = self._process_linewidths() self.tlinewidths = tlinewidths tlinestyles = self._process_linestyles() + aa = self.antialiased + if aa is not None: + aa = (self.antialiased,) for level, width, lstyle, segs in \ zip(self.levels, tlinewidths, tlinestyles, self.allsegs): # Default zorder taken from LineCollection zorder = kwargs.get('zorder', 2) col = collections.LineCollection(segs, + antialiaseds = aa, linewidths = width, linestyle = lstyle, alpha=self.alpha, @@ -1358,6 +1369,10 @@ Override axis units by specifying an instance of a :class:`matplotlib.units.ConversionInterface`. + *antialiased*: [ True | False ] + enable antialiasing, overriding the defaults. For + filled contours, the default is True. For line contours, + it is taken from rcParams['lines.antialiased']. contour-only keyword arguments: @@ -1385,9 +1400,6 @@ contourf-only keyword arguments: - *antialiased*: [ True | False ] - enable antialiasing - *nchunk*: [ 0 | integer ] If 0, no subdivision of the domain. Specify a positive integer to divide the domain into subdomains of roughly *nchunk* by *nchunk* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |