@@ -5599,7 +5599,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
5599
5599
return im
5600
5600
5601
5601
@staticmethod
5602
- def _pcolorargs (funcname , * args , allmatch = False ):
5602
+ def _pcolorargs (funcname , * args , allmatch = False , dropdata = True ):
5603
5603
# If allmatch is True, then the incoming X, Y, C must have matching
5604
5604
# dimensions, taking into account that X and Y can be 1-D rather than
5605
5605
# 2-D. This perfect match is required for Gouraud shading. For flat
@@ -5661,14 +5661,34 @@ def _pcolorargs(funcname, *args, allmatch=False):
5661
5661
raise TypeError ('Dimensions of C %s are incompatible with'
5662
5662
' X (%d) and/or Y (%d); see help(%s)' % (
5663
5663
C .shape , Nx , Ny , funcname ))
5664
- C = C [:Ny - 1 , :Nx - 1 ]
5664
+
5665
+ if dropdata :
5666
+ C = C [:Ny - 1 , :Nx - 1 ]
5667
+ else :
5668
+ def _interp_grid (X ):
5669
+ # helper for below
5670
+ dX = np .diff (X , axis = 1 )/ 2.
5671
+ X = np .hstack ((X [:, [0 ]] - dX [:, [0 ]],
5672
+ X [:, :- 1 ] + dX ,
5673
+ X [:, [- 1 ]] + dX [:, [- 1 ]])
5674
+ )
5675
+ return X
5676
+
5677
+ if ncols == Nx :
5678
+ X = _interp_grid (X )
5679
+ Y = _interp_grid (Y )
5680
+
5681
+ if nrows == Ny :
5682
+ X = _interp_grid (X .T ).T
5683
+ Y = _interp_grid (Y .T ).T
5684
+
5665
5685
C = cbook .safe_masked_invalid (C )
5666
5686
return X , Y , C
5667
5687
5668
5688
@_preprocess_data ()
5669
5689
@docstring .dedent_interpd
5670
5690
def pcolor (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5671
- vmax = None , ** kwargs ):
5691
+ vmax = None , dropdata = True , ** kwargs ):
5672
5692
r"""
5673
5693
Create a pseudocolor plot with a non-regular rectangular grid.
5674
5694
@@ -5707,7 +5727,8 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5707
5727
5708
5728
The dimensions of *X* and *Y* should be one greater than those of
5709
5729
*C*. Alternatively, *X*, *Y* and *C* may have equal dimensions, in
5710
- which case the last row and column of *C* will be ignored.
5730
+ which case the last row and column of *C* will be ignored if
5731
+ *dropdata* is True (see below).
5711
5732
5712
5733
If *X* and/or *Y* are 1-D arrays or column vectors they will be
5713
5734
expanded as needed into the appropriate 2-D arrays, making a
@@ -5747,6 +5768,12 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5747
5768
snap : bool, default: False
5748
5769
Whether to snap the mesh to pixel boundaries.
5749
5770
5771
+ dropdata: bool, default: True
5772
+ If True (default), and X and Y are the same size as C in their
5773
+ respective dimensions, drop the last element of C in both
5774
+ dimensions. If False, interpolate X and Y to their midpoints
5775
+ and extrapolate their endpoints.
5776
+
5750
5777
Returns
5751
5778
-------
5752
5779
collection : `matplotlib.collections.Collection`
@@ -5802,7 +5829,8 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5802
5829
Note: This behavior is different from MATLAB's ``pcolor()``, which
5803
5830
always discards the last row and column of *C*.
5804
5831
"""
5805
- X , Y , C = self ._pcolorargs ('pcolor' , * args , allmatch = False )
5832
+ X , Y , C = self ._pcolorargs ('pcolor' , * args , dropdata = dropdata ,
5833
+ allmatch = False )
5806
5834
Ny , Nx = X .shape
5807
5835
5808
5836
# unit conversion allows e.g. datetime objects as axis values
@@ -5899,7 +5927,8 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5899
5927
@_preprocess_data ()
5900
5928
@docstring .dedent_interpd
5901
5929
def pcolormesh (self , * args , alpha = None , norm = None , cmap = None , vmin = None ,
5902
- vmax = None , shading = 'flat' , antialiased = False , ** kwargs ):
5930
+ vmax = None , shading = 'flat' , antialiased = False ,
5931
+ dropdata = True , ** kwargs ):
5903
5932
"""
5904
5933
Create a pseudocolor plot with a non-regular rectangular grid.
5905
5934
@@ -5938,7 +5967,8 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5938
5967
5939
5968
The dimensions of *X* and *Y* should be one greater than those of
5940
5969
*C*. Alternatively, *X*, *Y* and *C* may have equal dimensions, in
5941
- which case the last row and column of *C* will be ignored.
5970
+ which case the last row and column of *C* will be ignored, unless
5971
+ *dropdata* is *False* (see below).
5942
5972
5943
5973
If *X* and/or *Y* are 1-D arrays or column vectors they will be
5944
5974
expanded as needed into the appropriate 2-D arrays, making a
@@ -5987,6 +6017,12 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
5987
6017
snap : bool, default: False
5988
6018
Whether to snap the mesh to pixel boundaries.
5989
6019
6020
+ dropdata: bool, default: True
6021
+ If True (default), and X and Y are the same size as C in their
6022
+ respective dimensions, drop the last element of C in both
6023
+ dimensions. If False, interpolate X and Y to their midpoints
6024
+ and extrapolate their endpoints.
6025
+
5990
6026
Returns
5991
6027
-------
5992
6028
mesh : `matplotlib.collections.QuadMesh`
@@ -6058,7 +6094,8 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6058
6094
6059
6095
allmatch = (shading == 'gouraud' )
6060
6096
6061
- X , Y , C = self ._pcolorargs ('pcolormesh' , * args , allmatch = allmatch )
6097
+ X , Y , C = self ._pcolorargs ('pcolormesh' , * args ,
6098
+ allmatch = allmatch , dropdata = dropdata )
6062
6099
Ny , Nx = X .shape
6063
6100
X = X .ravel ()
6064
6101
Y = Y .ravel ()
0 commit comments