Skip to content

Commit 0f876cf

Browse files
committed
Remove the forced disabling of antialiasing in contourf/pcolormesh/pcolor
1 parent 34b1d17 commit 0f876cf

4 files changed

Lines changed: 32 additions & 32 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Better antialiasing default for a few methods
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The plotting methods :meth:`Axes.contourf`, :meth:`Axes.pcolor`, and
4+
:meth:`Axes.pcolormesh` would previously default to no antialiasing when no
5+
edgecolor was specified due to a rendering artifact for faint lines between
6+
patches. That rendering artifact has now been fixed. These methods now use the
7+
value of rcParams ``patch.antialiased`` as the default for antialiasing.

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6693,15 +6693,6 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
66936693
66946694
Other Parameters
66956695
----------------
6696-
antialiaseds : bool, default: False
6697-
The default *antialiaseds* is False if the default
6698-
*edgecolors*\ ="none" is used. This eliminates artificial lines
6699-
at patch boundaries, and works regardless of the value of alpha.
6700-
If *edgecolors* is not "none", then the default *antialiaseds*
6701-
is taken from :rc:`patch.antialiased`.
6702-
Stroking the edges may be preferred if *alpha* is 1, but will
6703-
cause artifacts otherwise.
6704-
67056696
data : indexable object, optional
67066697
DATA_PARAMETER_PLACEHOLDER
67076698
@@ -6761,15 +6752,6 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
67616752
kwargs['edgecolors'] = kwargs.pop('edgecolor')
67626753
ec = kwargs.setdefault('edgecolors', 'none')
67636754

6764-
# aa setting will default via collections to patch.antialiased
6765-
# unless the boundary is not stroked, in which case the
6766-
# default will be False; with unstroked boundaries, aa
6767-
# makes artifacts that are often disturbing.
6768-
if 'antialiaseds' in kwargs:
6769-
kwargs['antialiased'] = kwargs.pop('antialiaseds')
6770-
if 'antialiased' not in kwargs and cbook._str_lower_equal(ec, "none"):
6771-
kwargs['antialiased'] = False
6772-
67736755
kwargs.setdefault('snap', False)
67746756

67756757
if np.ma.isMaskedArray(X) or np.ma.isMaskedArray(Y):
@@ -6796,7 +6778,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
67966778
@_preprocess_data()
67976779
@_docstring.interpd
67986780
def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6799-
vmax=None, colorizer=None, shading=None, antialiased=False,
6781+
vmax=None, colorizer=None, shading=None,
68006782
**kwargs):
68016783
"""
68026784
Create a pseudocolor plot with a non-regular rectangular grid.
@@ -7007,7 +6989,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
70076989
kwargs.setdefault('snap', mpl.rcParams['pcolormesh.snap'])
70086990

70096991
collection = mcoll.QuadMesh(
7010-
coords, antialiased=antialiased, shading=shading,
6992+
coords, shading=shading,
70116993
array=C, colorizer=colorizer, alpha=alpha, **kwargs)
70126994
collection._scale_norm(norm, vmin, vmax)
70136995

@@ -7206,7 +7188,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
72067188
collection = mcoll.QuadMesh(
72077189
coords, array=C,
72087190
alpha=alpha, cmap=cmap, norm=norm, colorizer=colorizer,
7209-
antialiased=False, edgecolors="none")
7191+
edgecolors="none")
72107192
self.add_collection(collection, autolim=False)
72117193
xl, xr, yb, yt = x.min(), x.max(), y.min(), y.max()
72127194
ret = collection

‎lib/matplotlib/collections.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,6 +2581,12 @@ def draw(self, renderer):
25812581
renderer.draw_gouraud_triangles(
25822582
gc, triangles, colors, transform.frozen())
25832583
else:
2584+
# If supported by the renderer, we draw antialiased patches without strokes
2585+
# in an isolated blend group using the "plus" blend mode so that the
2586+
# fractional alphas at edges are added to make the intended total alpha.
2587+
# If the alphas were instead blended as if they were unrelated opacities,
2588+
# the resulting alpha would be smaller (i.e., more transparent), which would
2589+
# manifest as slightly transparent line artifacts along patch edges.
25842590
isolate = (renderer._use_blend_group_for_pcolor and self._antialiased
25852591
and (self._edgecolors.size == 0 or self._edgecolors[0][3] == 0))
25862592
if isolate:
@@ -2701,6 +2707,12 @@ def get_edgecolor(self):
27012707

27022708
@artist.allow_rasterization
27032709
def draw(self, renderer):
2710+
# If supported by the renderer, we draw antialiased patches without strokes
2711+
# in an isolated blend group using the "plus" blend mode so that the
2712+
# fractional alphas at edges are added to make the intended total alpha.
2713+
# If the alphas were instead blended as if they were unrelated opacities,
2714+
# the resulting alpha would be smaller (i.e., more transparent), which would
2715+
# manifest as slightly transparent line artifacts along patch edges.
27042716
isolate = (renderer._use_blend_group_for_pcolor and np.all(self._antialiaseds)
27052717
and (self._edgecolors.size == 0 or self._edgecolors[0][3] == 0))
27062718
if isolate:

‎lib/matplotlib/contour.py‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,6 @@ def __init__(self, ax, *args,
673673
Keyword arguments are as described in the docstring of
674674
`~.Axes.contour`.
675675
"""
676-
if antialiased is None and filled:
677-
# Eliminate artifacts; we are not stroking the boundaries.
678-
antialiased = False
679-
# The default for line contours will be taken from the
680-
# LineCollection default, which uses :rc:`lines.antialiased`.
681676
super().__init__(
682677
antialiaseds=antialiased,
683678
alpha=alpha,
@@ -1287,6 +1282,12 @@ def draw(self, renderer):
12871282
n_paths = len(paths)
12881283
edgecolors = self.get_edgecolors()
12891284
if not self.filled or all(hatch is None for hatch in self.hatches):
1285+
# If supported by the renderer, we draw antialiased patches without strokes
1286+
# in an isolated blend group using the "plus" blend mode so that the
1287+
# fractional alphas at edges are added to make the intended total alpha.
1288+
# If the alphas were instead blended as if they were unrelated opacities,
1289+
# the resulting alpha would be smaller (i.e., more transparent), which would
1290+
# manifest as slightly transparent line artifacts along patch edges.
12901291
isolate = (renderer._use_blend_group_for_contourf and
12911292
self.filled and self.get_antialiased() and
12921293
(edgecolors.size == 0 or edgecolors[0][3] == 0))
@@ -1660,18 +1661,16 @@ def _initialize_x_y(self, z):
16601661
:class:`matplotlib.units.ConversionInterface`.
16611662
16621663
antialiased : bool, optional
1663-
Enable antialiasing, overriding the defaults. For
1664-
filled contours, the default is *False*. For line contours,
1665-
it is taken from :rc:`lines.antialiased`.
1664+
Enable or disable antialiasing, overriding the defaults.
1665+
For filled contours, the default value is :rc:`patch.antialiased.`
1666+
For line contours, the default value is :rc:`lines.antialiased`.
16661667
16671668
nchunk : int >= 0, optional
16681669
If 0, no subdivision of the domain. Specify a positive integer to
16691670
divide the domain into subdomains of *nchunk* by *nchunk* quads.
16701671
Chunking reduces the maximum length of polygons generated by the
16711672
contouring algorithm which reduces the rendering workload passed
1672-
on to the backend and also requires slightly less RAM. It can
1673-
however introduce rendering artifacts at chunk boundaries depending
1674-
on the backend, the *antialiased* flag and value of *alpha*.
1673+
on to the backend and also requires slightly less RAM.
16751674
16761675
linewidths : float or array-like, default: :rc:`contour.linewidth`
16771676
*Only applies to* `.contour`.

0 commit comments

Comments
 (0)