@@ -5772,9 +5772,13 @@ def _interp_grid(X):
5772
5772
"This may lead to incorrectly calculated cell "
5773
5773
"edges, in which case, please supply "
5774
5774
f"explicit cell edges to { funcname } ." )
5775
- X = np .hstack ((X [:, [0 ]] - dX [:, [0 ]],
5776
- X [:, :- 1 ] + dX ,
5777
- X [:, [- 1 ]] + dX [:, [- 1 ]]))
5775
+ if isinstance (X , np .ma .core .MaskedArray ):
5776
+ hstack = np .ma .hstack
5777
+ else :
5778
+ hstack = np .hstack
5779
+ X = hstack ((X [:, [0 ]] - dX [:, [0 ]],
5780
+ X [:, :- 1 ] + dX ,
5781
+ X [:, [- 1 ]] + dX [:, [- 1 ]]))
5778
5782
else :
5779
5783
# This is just degenerate, but we can't reliably guess
5780
5784
# a dX if there is just one value.
@@ -5892,7 +5896,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
5892
5896
5893
5897
Returns
5894
5898
-------
5895
- `matplotlib.collections.Collection `
5899
+ `matplotlib.collections.PolyQuadMesh `
5896
5900
5897
5901
Other Parameters
5898
5902
----------------
@@ -5910,7 +5914,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
5910
5914
5911
5915
**kwargs
5912
5916
Additionally, the following arguments are allowed. They are passed
5913
- along to the `~matplotlib.collections.PolyCollection ` constructor:
5917
+ along to the `~matplotlib.collections.PolyQuadMesh ` constructor:
5914
5918
5915
5919
%(PolyCollection:kwdoc)s
5916
5920
@@ -5944,35 +5948,6 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
5944
5948
shading = shading .lower ()
5945
5949
X , Y , C , shading = self ._pcolorargs ('pcolor' , * args , shading = shading ,
5946
5950
kwargs = kwargs )
5947
- Ny , Nx = X .shape
5948
-
5949
- # convert to MA, if necessary.
5950
- C = ma .asarray (C )
5951
- X = ma .asarray (X )
5952
- Y = ma .asarray (Y )
5953
-
5954
- mask = ma .getmaskarray (X ) + ma .getmaskarray (Y )
5955
- xymask = (mask [0 :- 1 , 0 :- 1 ] + mask [1 :, 1 :] +
5956
- mask [0 :- 1 , 1 :] + mask [1 :, 0 :- 1 ])
5957
- # don't plot if C or any of the surrounding vertices are masked.
5958
- mask = ma .getmaskarray (C ) + xymask
5959
-
5960
- unmask = ~ mask
5961
- X1 = ma .filled (X [:- 1 , :- 1 ])[unmask ]
5962
- Y1 = ma .filled (Y [:- 1 , :- 1 ])[unmask ]
5963
- X2 = ma .filled (X [1 :, :- 1 ])[unmask ]
5964
- Y2 = ma .filled (Y [1 :, :- 1 ])[unmask ]
5965
- X3 = ma .filled (X [1 :, 1 :])[unmask ]
5966
- Y3 = ma .filled (Y [1 :, 1 :])[unmask ]
5967
- X4 = ma .filled (X [:- 1 , 1 :])[unmask ]
5968
- Y4 = ma .filled (Y [:- 1 , 1 :])[unmask ]
5969
- npoly = len (X1 )
5970
-
5971
- xy = np .stack ([X1 , Y1 , X2 , Y2 , X3 , Y3 , X4 , Y4 , X1 , Y1 ], axis = - 1 )
5972
- verts = xy .reshape ((npoly , 5 , 2 ))
5973
-
5974
- C = ma .filled (C [:Ny - 1 , :Nx - 1 ])[unmask ]
5975
-
5976
5951
linewidths = (0.25 ,)
5977
5952
if 'linewidth' in kwargs :
5978
5953
kwargs ['linewidths' ] = kwargs .pop ('linewidth' )
@@ -5986,19 +5961,30 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
5986
5961
# unless the boundary is not stroked, in which case the
5987
5962
# default will be False; with unstroked boundaries, aa
5988
5963
# makes artifacts that are often disturbing.
5989
- if 'antialiased ' in kwargs :
5990
- kwargs ['antialiaseds ' ] = kwargs .pop ('antialiased ' )
5991
- if 'antialiaseds ' not in kwargs and cbook ._str_lower_equal (ec , "none" ):
5992
- kwargs ['antialiaseds ' ] = False
5964
+ if 'antialiaseds ' in kwargs :
5965
+ kwargs ['antialiased ' ] = kwargs .pop ('antialiaseds ' )
5966
+ if 'antialiased ' not in kwargs and cbook ._str_lower_equal (ec , "none" ):
5967
+ kwargs ['antialiased ' ] = False
5993
5968
5994
5969
kwargs .setdefault ('snap' , False )
5995
5970
5996
- collection = mcoll .PolyCollection (
5997
- verts , array = C , cmap = cmap , norm = norm , alpha = alpha , ** kwargs )
5998
- collection ._scale_norm (norm , vmin , vmax )
5971
+ if (isinstance (X , np .ma .MaskedArray )
5972
+ or isinstance (Y , np .ma .MaskedArray )):
5973
+ stack = np .ma .stack
5974
+ X = np .ma .asarray (X )
5975
+ Y = np .ma .asarray (Y )
5976
+ # For bounds collections later
5977
+ x = X .compressed ()
5978
+ y = Y .compressed ()
5979
+ else :
5980
+ stack = np .stack
5981
+ x = X
5982
+ y = Y
5983
+ coords = stack ([X , Y ], axis = - 1 )
5999
5984
6000
- x = X .compressed ()
6001
- y = Y .compressed ()
5985
+ collection = mcoll .PolyQuadMesh (
5986
+ coords , array = C , cmap = cmap , norm = norm , alpha = alpha , ** kwargs )
5987
+ collection ._scale_norm (norm , vmin , vmax )
6002
5988
6003
5989
# Transform from native to data coordinates?
6004
5990
t = collection ._transform
0 commit comments