@@ -5238,6 +5238,7 @@ def _pcolorargs(funcname, *args, **kw):
5238
5238
# required for flat shading.
5239
5239
5240
5240
allmatch = kw .pop ("allmatch" , False )
5241
+ interpolate_grids = kw .pop ("interpolate_grids" , False )
5241
5242
5242
5243
if len (args ) == 1 :
5243
5244
C = np .asanyarray (args [0 ])
@@ -5276,15 +5277,25 @@ def _pcolorargs(funcname, *args, **kw):
5276
5277
C .shape , Nx , Ny , funcname ))
5277
5278
5278
5279
if allmatch :
5279
- if numRows == Ny - 1 :
5280
- Y_new = 0.5 * Y [:numRows , :numCols ]
5281
- Y_new += 0.5 * Y [1 :, 1 :]
5282
- Y = Y_new
5283
-
5284
- if numCols == Nx - 1 :
5285
- X_new = 0.5 * X [:numRows , :numCols ]
5286
- X_new += 0.5 * X [1 :, 1 :]
5287
- X = X_new
5280
+ if numRows != Ny or numCols != Nx :
5281
+ if interpolate_grids :
5282
+
5283
+ if numRows == Ny - 1 :
5284
+ Y_new = 0.5 * Y [:numRows , :numCols ]
5285
+ Y_new += 0.5 * Y [1 :, 1 :]
5286
+ Y = Y_new
5287
+
5288
+ if numCols == Nx - 1 :
5289
+ X_new = 0.5 * X [:numRows , :numCols ]
5290
+ X_new += 0.5 * X [1 :, 1 :]
5291
+ X = X_new
5292
+
5293
+ else :
5294
+
5295
+ raise TypeError ('Dimensions of C %s are incompatible with'
5296
+ ' X (%d) and/or Y (%d); see help(%s)' % (
5297
+ C .shape , Nx , Ny , funcname ))
5298
+
5288
5299
else :
5289
5300
C = C [:Ny - 1 , :Nx - 1 ]
5290
5301
C = cbook .safe_masked_invalid (C )
@@ -5574,6 +5585,22 @@ def pcolormesh(self, *args, **kwargs):
5574
5585
contrast, :func:`~matplotlib.pyplot.pcolor` simply does not
5575
5586
draw quadrilaterals with masked colors or vertices.
5576
5587
5588
+ If flat shading is used, the arrays *X* and *Y* are assumed to
5589
+ specify the boundary points of quadrilaterals with colors given
5590
+ in *C*. They should thus each have one more column and row than
5591
+ the *C* array. For compatibility with Matlab as well as convenience,
5592
+ the case in which *X*, *Y*, *C* have the same dimension
5593
+ is also accepted and handled by dropping the last row and column
5594
+ of *C*.
5595
+
5596
+ If Gouraud shading is used, the arrays *X* and *Y* are assumed to
5597
+ specify the centers of the quadrilaterals and thus should have the
5598
+ same dimensions as *C*. If this is not the case and error will be
5599
+ thrown. However, for compatibility with the flat shading case, the
5600
+ ``interpolate_grids`` keyword argument is provided which when
5601
+ set to ``True`` will cause *X* and *Y* to be linearly interpolated
5602
+ to obtain the corresponding centerpoints.
5603
+
5577
5604
Keyword arguments:
5578
5605
5579
5606
*cmap*: [ *None* | Colormap ]
@@ -5612,6 +5639,19 @@ def pcolormesh(self, *args, **kwargs):
5612
5639
*alpha*: ``0 <= scalar <= 1`` or *None*
5613
5640
the alpha blending value
5614
5641
5642
+ *interpolate_grids*: [``True`` | ``False``]
5643
+
5644
+ When set to ``True`` and Gouraud shading is used with *X* and
5645
+ *Y* with one more row and column than *C*, *X* and *Y* will be
5646
+ linearly interpolated to obtain the centers of the quadrilaterals
5647
+ described by *X* and *Y*.
5648
+
5649
+ When set to ``False`` the above case with cause an error to be
5650
+ thrown.
5651
+
5652
+ Ignored when ``shading = flat``.
5653
+
5654
+
5615
5655
Return value is a :class:`matplotlib.collections.QuadMesh`
5616
5656
object.
5617
5657
@@ -5637,11 +5677,15 @@ def pcolormesh(self, *args, **kwargs):
5637
5677
vmax = kwargs .pop ('vmax' , None )
5638
5678
shading = kwargs .pop ('shading' , 'flat' ).lower ()
5639
5679
antialiased = kwargs .pop ('antialiased' , False )
5680
+ interpolate_grids = kwargs .pop ('interpolate_grids' , False )
5640
5681
kwargs .setdefault ('edgecolors' , 'None' )
5641
5682
5642
5683
allmatch = (shading == 'gouraud' )
5643
5684
5644
- X , Y , C = self ._pcolorargs ('pcolormesh' , * args , allmatch = allmatch )
5685
+ X , Y , C = self ._pcolorargs ('pcolormesh' ,
5686
+ * args ,
5687
+ allmatch = allmatch ,
5688
+ interpolate_grids = interpolate_grids )
5645
5689
Ny , Nx = X .shape
5646
5690
X = X .ravel ()
5647
5691
Y = Y .ravel ()
0 commit comments