@@ -1723,7 +1723,7 @@ def pcolormesh(self, *args, **kwargs):
17231723 """
17241724 # Add in an argument checker to handle Matplotlib's potential
17251725 # interpolation when coordinate wraps are involved
1726- args = self ._wrap_args (* args , ** kwargs )
1726+ args , kwargs = self ._wrap_args (* args , ** kwargs )
17271727 result = super ().pcolormesh (* args , ** kwargs )
17281728 # Wrap the quadrilaterals if necessary
17291729 result = self ._wrap_quadmesh (result , ** kwargs )
@@ -1745,8 +1745,11 @@ def _wrap_args(self, *args, **kwargs):
17451745 if not (kwargs .get ('shading' , default_shading ) in
17461746 ('nearest' , 'auto' ) and len (args ) == 3 and
17471747 getattr (kwargs .get ('transform' ), '_wrappable' , False )):
1748- return args
1748+ return args , kwargs
17491749
1750+ # We have changed the shading from nearest/auto to flat
1751+ # due to the addition of an extra coordinate
1752+ kwargs ['shading' ] = 'flat'
17501753 X = np .asanyarray (args [0 ])
17511754 Y = np .asanyarray (args [1 ])
17521755 nrows , ncols = np .asanyarray (args [2 ]).shape
@@ -1782,7 +1785,7 @@ def _interp_grid(X, wrap=0):
17821785 X = _interp_grid (X .T , wrap = xwrap ).T
17831786 Y = _interp_grid (Y .T ).T
17841787
1785- return (X , Y , args [2 ])
1788+ return (X , Y , args [2 ]), kwargs
17861789
17871790 def _wrap_quadmesh (self , collection , ** kwargs ):
17881791 """
@@ -1798,8 +1801,13 @@ def _wrap_quadmesh(self, collection, **kwargs):
17981801 # Get the quadmesh data coordinates
17991802 coords = collection ._coordinates
18001803 Ny , Nx , _ = coords .shape
1804+ if kwargs .get ('shading' ) == 'gouraud' :
1805+ # Gouraud shading has the same shape for coords and data
1806+ data_shape = Ny , Nx
1807+ else :
1808+ data_shape = Ny - 1 , Nx - 1
18011809 # data array
1802- C = collection .get_array ().reshape (( Ny - 1 , Nx - 1 ) )
1810+ C = collection .get_array ().reshape (data_shape )
18031811
18041812 transformed_pts = self .projection .transform_points (
18051813 t , coords [..., 0 ], coords [..., 1 ])
@@ -1828,6 +1836,23 @@ def _wrap_quadmesh(self, collection, **kwargs):
18281836 # No wrapping needed
18291837 return collection
18301838
1839+ # Wrapping with gouraud shading is error-prone. We will do our best,
1840+ # but pcolor does not handle gouraud shading, so there needs to be
1841+ # another way to handle the wrapped cells.
1842+ if kwargs .get ('shading' ) == 'gouraud' :
1843+ warnings .warn ("Handling wrapped coordinates with gouraud "
1844+ "shading is likely to introduce artifacts. "
1845+ "It is recommended to remove the wrap manually "
1846+ "before calling pcolormesh." )
1847+ # With gouraud shading, we actually want an (Ny, Nx) shaped mask
1848+ gmask = np .zeros (data_shape , dtype = bool )
1849+ # If any of the cells were wrapped, apply it to all 4 corners
1850+ gmask [:- 1 , :- 1 ] |= mask
1851+ gmask [1 :, :- 1 ] |= mask
1852+ gmask [1 :, 1 :] |= mask
1853+ gmask [:- 1 , 1 :] |= mask
1854+ mask = gmask
1855+
18311856 # We have quadrilaterals that cross the wrap boundary
18321857 # Now, we need to update the original collection with
18331858 # a mask over those cells and use pcolor to draw those
@@ -1908,7 +1933,11 @@ def pcolor(self, *args, **kwargs):
19081933 """
19091934 # Add in an argument checker to handle Matplotlib's potential
19101935 # interpolation when coordinate wraps are involved
1911- args = self ._wrap_args (* args , ** kwargs )
1936+ args , kwargs = self ._wrap_args (* args , ** kwargs )
1937+ if matplotlib .__version__ < "3.3" :
1938+ # MPL 3.3 introduced the shading option, and it isn't
1939+ # handled before that for pcolor calls.
1940+ kwargs .pop ('shading' , None )
19121941 result = super ().pcolor (* args , ** kwargs )
19131942
19141943 # Update the datalim for this pcolor.
0 commit comments