13
13
import numpy as np
14
14
from numpy import ma
15
15
import matplotlib ._cntr as _cntr
16
+ import matplotlib ._contour as _contour
16
17
import matplotlib .path as mpath
17
18
import matplotlib .ticker as ticker
18
19
import matplotlib .cm as cm
@@ -1438,13 +1439,23 @@ def _process_args(self, *args, **kwargs):
1438
1439
self .levels = args [0 ].levels
1439
1440
self .zmin = args [0 ].zmin
1440
1441
self .zmax = args [0 ].zmax
1442
+ self ._corner_mask = args [0 ]._corner_mask
1441
1443
else :
1442
1444
x , y , z = self ._contour_args (args , kwargs )
1443
1445
1444
1446
_mask = ma .getmask (z )
1445
- if _mask is ma .nomask :
1447
+ if _mask is ma .nomask or not _mask . any () :
1446
1448
_mask = None
1447
- C = _cntr .Cntr (x , y , z .filled (), _mask )
1449
+
1450
+ self ._corner_mask = kwargs .get ('corner_mask' , None )
1451
+ if self ._corner_mask is None :
1452
+ self ._corner_mask = mpl .rcParams ['contour.corner_mask' ]
1453
+
1454
+ if self ._corner_mask == 'legacy' :
1455
+ C = _cntr .Cntr (x , y , z .filled (), _mask )
1456
+ else :
1457
+ C = _contour .QuadContourGenerator (
1458
+ x , y , z .filled (), _mask , self ._corner_mask , self .nchunk )
1448
1459
1449
1460
t = self .get_transform ()
1450
1461
@@ -1476,19 +1487,27 @@ def _get_allsegs_and_allkinds(self):
1476
1487
lowers , uppers = self ._get_lowers_and_uppers ()
1477
1488
allkinds = []
1478
1489
for level , level_upper in zip (lowers , uppers ):
1479
- nlist = self .Cntr .trace (level , level_upper ,
1480
- nchunk = self .nchunk )
1481
- nseg = len (nlist ) // 2
1482
- segs = nlist [:nseg ]
1483
- kinds = nlist [nseg :]
1490
+ if self ._corner_mask == 'legacy' :
1491
+ nlist = self .Cntr .trace (level , level_upper ,
1492
+ nchunk = self .nchunk )
1493
+ nseg = len (nlist ) // 2
1494
+ segs = nlist [:nseg ]
1495
+ kinds = nlist [nseg :]
1496
+ else :
1497
+ nlist = self .Cntr .create_filled_contour (level , level_upper )
1498
+ segs = nlist [::2 ]
1499
+ kinds = nlist [1 ::2 ]
1484
1500
allsegs .append (segs )
1485
1501
allkinds .append (kinds )
1486
1502
else :
1487
1503
allkinds = None
1488
1504
for level in self .levels :
1489
- nlist = self .Cntr .trace (level )
1490
- nseg = len (nlist ) // 2
1491
- segs = nlist [:nseg ]
1505
+ if self ._corner_mask == 'legacy' :
1506
+ nlist = self .Cntr .trace (level )
1507
+ nseg = len (nlist ) // 2
1508
+ segs = nlist [:nseg ]
1509
+ else :
1510
+ segs = self .Cntr .create_contour (level )
1492
1511
allsegs .append (segs )
1493
1512
return allsegs , allkinds
1494
1513
@@ -1672,6 +1691,20 @@ def _initialize_x_y(self, z):
1672
1691
1673
1692
Optional keyword arguments:
1674
1693
1694
+ *corner_mask*: [ *True* | *False* | 'legacy' ]
1695
+ Enable/disable corner masking, which only has an effect if *Z* is
1696
+ a masked array. If *False*, any quad touching a masked point is
1697
+ masked out. If *True*, only the triangular corners of quads
1698
+ nearest those points are always masked out, other triangular
1699
+ corners comprising three unmasked points are contoured as usual.
1700
+ If 'legacy', the old contouring algorithm is used, which is
1701
+ equivalent to *False* and is deprecated, only remaining whilst the
1702
+ new algorithm is tested fully.
1703
+
1704
+ If not specified, the default is taken from
1705
+ rcParams['contour.corner_mask'], which is True unless it has
1706
+ been modified.
1707
+
1675
1708
*colors*: [ *None* | string | (mpl_colors) ]
1676
1709
If *None*, the colormap specified by cmap will be used.
1677
1710
@@ -1750,6 +1783,15 @@ def _initialize_x_y(self, z):
1750
1783
filled contours, the default is *True*. For line contours,
1751
1784
it is taken from rcParams['lines.antialiased'].
1752
1785
1786
+ *nchunk*: [ 0 | integer ]
1787
+ If 0, no subdivision of the domain. Specify a positive integer to
1788
+ divide the domain into subdomains of *nchunk* by *nchunk* quads.
1789
+ Chunking reduces the maximum length of polygons generated by the
1790
+ contouring algorithm which reduces the rendering workload passed
1791
+ on to the backend and also requires slightly less RAM. It can
1792
+ however introduce rendering artifacts at chunk boundaries depending
1793
+ on the backend, the *antialiased* flag and value of *alpha*.
1794
+
1753
1795
contour-only keyword arguments:
1754
1796
1755
1797
*linewidths*: [ *None* | number | tuple of numbers ]
@@ -1774,13 +1816,6 @@ def _initialize_x_y(self, z):
1774
1816
1775
1817
contourf-only keyword arguments:
1776
1818
1777
- *nchunk*: [ 0 | integer ]
1778
- If 0, no subdivision of the domain. Specify a positive integer to
1779
- divide the domain into subdomains of roughly *nchunk* by *nchunk*
1780
- points. This may never actually be advantageous, so this option may
1781
- be removed. Chunking introduces artifacts at the chunk boundaries
1782
- unless *antialiased* is *False*.
1783
-
1784
1819
*hatches*:
1785
1820
A list of cross hatch patterns to use on the filled areas.
1786
1821
If None, no hatching will be added to the contour.
@@ -1802,4 +1837,6 @@ def _initialize_x_y(self, z):
1802
1837
.. plot:: mpl_examples/pylab_examples/contour_demo.py
1803
1838
1804
1839
.. plot:: mpl_examples/pylab_examples/contourf_demo.py
1840
+
1841
+ .. plot:: mpl_examples/pylab_examples/contour_corner_mask.py
1805
1842
"""
0 commit comments