Skip to content

Commit ee15518

Browse files
authored
avoid-unnecessary-warning-in-_pcolorargs-function
Within the `_interp_grid function`, unnecessary warnings may be triggered when expanding the grid coordinates. As long as the X coordinates and Y coordinates remain monotonic in their respective directions, negative area grids can be avoided. Therefore, the `require_monotonicity` keyword has been added to avoid triggering monotonicity warnings indiscriminately when calling the function.
1 parent 7025fb9 commit ee15518

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6027,8 +6027,11 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
60276027
# grid is specified at the center, so define corners
60286028
# at the midpoints between the grid centers and then use the
60296029
# flat algorithm.
6030-
def _interp_grid(X):
6031-
# helper for below
6030+
def _interp_grid(X, require_monotonicity=False):
6031+
# helper for below. To ensure the cell edges are calculated
6032+
# correctly, when expanding columns, the monotonicity of
6033+
# X coords needs to be checked. When expanding rows, the
6034+
# monotonicity of Y coords needs to be checked.
60326035
if np.shape(X)[1] > 1:
60336036
dX = np.diff(X, axis=1) * 0.5
60346037
if not (np.all(dX >= 0) or np.all(dX <= 0)):
@@ -6051,11 +6054,11 @@ def _interp_grid(X):
60516054
return X
60526055

60536056
if ncols == Nx:
6054-
X = _interp_grid(X)
6057+
X = _interp_grid(X, require_monotonicity=True)
60556058
Y = _interp_grid(Y)
60566059
if nrows == Ny:
60576060
X = _interp_grid(X.T).T
6058-
Y = _interp_grid(Y.T).T
6061+
Y = _interp_grid(Y.T, require_monotonicity=True).T
60596062
shading = 'flat'
60606063

60616064
C = cbook.safe_masked_invalid(C, copy=True)

0 commit comments

Comments
 (0)