@@ -1793,7 +1793,7 @@ def pcolormesh(self, *args, **kwargs):
17931793 """
17941794 # Add in an argument checker to handle Matplotlib's potential
17951795 # interpolation when coordinate wraps are involved
1796- args = self ._wrap_args (* args , ** kwargs )
1796+ args , kwargs = self ._wrap_args (* args , ** kwargs )
17971797 result = matplotlib .axes .Axes .pcolormesh (self , * args , ** kwargs )
17981798 # Wrap the quadrilaterals if necessary
17991799 result = self ._wrap_quadmesh (result , ** kwargs )
@@ -1815,8 +1815,11 @@ def _wrap_args(self, *args, **kwargs):
18151815 if not (kwargs .get ('shading' , default_shading ) in
18161816 ('nearest' , 'auto' ) and len (args ) == 3 and
18171817 getattr (kwargs .get ('transform' ), '_wrappable' , False )):
1818- return args
1818+ return args , kwargs
18191819
1820+ # We have changed the shading from nearest/auto to flat
1821+ # due to the addition of an extra coordinate
1822+ kwargs ['shading' ] = 'flat'
18201823 X = np .asanyarray (args [0 ])
18211824 Y = np .asanyarray (args [1 ])
18221825 nrows , ncols = np .asanyarray (args [2 ]).shape
@@ -1852,7 +1855,7 @@ def _interp_grid(X, wrap=0):
18521855 X = _interp_grid (X .T , wrap = xwrap ).T
18531856 Y = _interp_grid (Y .T ).T
18541857
1855- return (X , Y , args [2 ])
1858+ return (X , Y , args [2 ]), kwargs
18561859
18571860 def _wrap_quadmesh (self , collection , ** kwargs ):
18581861 """
@@ -1868,8 +1871,13 @@ def _wrap_quadmesh(self, collection, **kwargs):
18681871 # Get the quadmesh data coordinates
18691872 coords = collection ._coordinates
18701873 Ny , Nx , _ = coords .shape
1874+ if kwargs .get ('shading' ) == 'gouraud' :
1875+ # Gouraud shading has the same shape for coords and data
1876+ data_shape = Ny , Nx
1877+ else :
1878+ data_shape = Ny - 1 , Nx - 1
18711879 # data array
1872- C = collection .get_array ().reshape (( Ny - 1 , Nx - 1 ) )
1880+ C = collection .get_array ().reshape (data_shape )
18731881
18741882 transformed_pts = self .projection .transform_points (
18751883 t , coords [..., 0 ], coords [..., 1 ])
@@ -1898,6 +1906,23 @@ def _wrap_quadmesh(self, collection, **kwargs):
18981906 # No wrapping needed
18991907 return collection
19001908
1909+ # Wrapping with gouraud shading is error-prone. We will do our best,
1910+ # but pcolor does not handle gouraud shading, so there needs to be
1911+ # another way to handle the wrapped cells.
1912+ if kwargs .get ('shading' ) == 'gouraud' :
1913+ warnings .warn ("Handling wrapped coordinates with gouraud "
1914+ "shading is likely to introduce artifacts. "
1915+ "It is recommended to remove the wrap manually "
1916+ "before calling pcolormesh." )
1917+ # With gouraud shading, we actually want an (Ny, Nx) shaped mask
1918+ gmask = np .zeros (data_shape , dtype = bool )
1919+ # If any of the cells were wrapped, apply it to all 4 corners
1920+ gmask [:- 1 , :- 1 ] |= mask
1921+ gmask [1 :, :- 1 ] |= mask
1922+ gmask [1 :, 1 :] |= mask
1923+ gmask [:- 1 , 1 :] |= mask
1924+ mask = gmask
1925+
19011926 # We have quadrilaterals that cross the wrap boundary
19021927 # Now, we need to update the original collection with
19031928 # a mask over those cells and use pcolor to draw those
@@ -1978,7 +2003,11 @@ def pcolor(self, *args, **kwargs):
19782003 """
19792004 # Add in an argument checker to handle Matplotlib's potential
19802005 # interpolation when coordinate wraps are involved
1981- args = self ._wrap_args (* args , ** kwargs )
2006+ args , kwargs = self ._wrap_args (* args , ** kwargs )
2007+ if matplotlib .__version__ < "3.3" :
2008+ # MPL 3.3 introduced the shading option, and it isn't
2009+ # handled before that for pcolor calls.
2010+ kwargs .pop ('shading' , None )
19822011 result = matplotlib .axes .Axes .pcolor (self , * args , ** kwargs )
19832012
19842013 # Update the datalim for this pcolor.
0 commit comments