Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6560,9 +6560,23 @@ def _interp_grid(X, require_monotonicity=False):
X[:, :-1] + dX,
X[:, [-1]] + dX[:, [-1]]))
else:
# This is just degenerate, but we can't reliably guess
# a dX if there is just one value.
X = np.hstack((X, X))
if require_monotonicity:
# Fallback if coordinate array has only one cell center
# so its corresponding cell size cannot be determined
# from neighboring centers.
_api.warn_external(
"A coordinate array contains a single cell center "
f"along one axis, so {funcname} cannot determine "
"a cell size in that direction to calculate the "
"cell edges. A default cell size is being used; "
f"supply explicit cell edges to {funcname} instead "
"to avoid this warning.")
dX = np.abs(X) * 0.5
dX[dX == 0] = 0.5
hstack = np.ma.hstack if np.ma.isMA(X) else np.hstack
X = hstack((X - dX, X + dX))
else:
X = np.hstack((X, X))
return X

if ncols == Nx:
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,20 @@ def test_pcolorargs():
# bad grid warnings.
ax.pcolormesh(X+10*noise_X, Y+10*noise_Y, Z, shading='auto')
assert len(record) == 2
# If the grid contains a single row and/or column for nearest shading,
# a warning is emitted and a default cell size is used.
x = [2, 4, 6]
y = [5]
Z = np.arange(3).reshape(1, 3)
with pytest.warns(UserWarning,
match='coordinate array contains a single cell center'):
ax.pcolormesh(x, y, Z)
with pytest.warns(UserWarning,
match='coordinate array contains a single cell center'):
ax.pcolormesh(y, x, Z.T)
with pytest.warns(UserWarning,
match='coordinate array contains a single cell center'):
ax.pcolormesh(y, y, Z[:, [0]])


def test_pcolormesh_underflow_error():
Expand Down
Loading