Skip to content

DOC: Correct shading behavior descriptions in pcolor/pcolormesh#31731

Merged
timhoffm merged 2 commits into
matplotlib:mainfrom
lucaznch:docs-pcolor-pcolormesh
Jun 5, 2026
Merged

DOC: Correct shading behavior descriptions in pcolor/pcolormesh#31731
timhoffm merged 2 commits into
matplotlib:mainfrom
lucaznch:docs-pcolor-pcolormesh

Conversation

@lucaznch
Copy link
Copy Markdown
Contributor

@lucaznch lucaznch commented May 22, 2026

PR summary

This PR fixes minor documentation inconsistencies shared by both pcolor and pcolormesh.

  • Incompatible X, Y, and C raise a TypeError rather than ValueError.
  • For shading='flat' when X, Y and C have the same shape as C, the last row/column of C is no longer dropped with a deprecation warning

The pcolormesh documentation fix already appears in #31362, but I noticed the same issue in pcolor as well, so I'm opening this separate PR to address both.

Example

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> nrows, ncols = 2, 3
>>> C = np.arange(nrows * ncols).reshape(nrows, ncols)
>>> x, y = np.arange(ncols + 1), np.arange(nrows + 1)

Using pcolor with shading='nearest' with incompatible X, Y and C:

>>> ax.pcolor(x, y, C, shading='nearest')
...
TypeError: Dimensions of C (2, 3) are incompatible with X (4) and/or Y (3); see help(pcolor)

Using pcolormesh with shading='flat' and X, Y having the same shape as C:

>>> ax.pcolormesh(x[:-1], y[:-1], C, shading='flat')
...
TypeError: Dimensions of C (2, 3) should be one smaller than X(3) and Y(2) while using shading='flat' see help(pcolormesh)

AI Disclosure

None.

PR checklist

@lucaznch
Copy link
Copy Markdown
Contributor Author

cc @timhoffm

lucaznch added 2 commits May 24, 2026 11:49
pcolor and pcolormesh raise TypeError
for incompatible grid and data dimensions.
When X, Y, C have the same shape, the last row/column
of C is no longer dropped with a deprecation warning
(a TypeError is raised instead).
@lucaznch lucaznch force-pushed the docs-pcolor-pcolormesh branch from f5b6b89 to 65e9ab1 Compare May 24, 2026 10:50
@timhoffm timhoffm added this to the v3.11.0 milestone Jun 5, 2026
@timhoffm timhoffm merged commit f501818 into matplotlib:main Jun 5, 2026
41 checks passed
@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Jun 5, 2026

Thanks @lucaznch!

timhoffm added a commit that referenced this pull request Jun 5, 2026
timhoffm added a commit that referenced this pull request Jun 5, 2026
…731-on-v3.11.x

Backport PR #31731 on branch v3.11.x (DOC: Correct shading behavior descriptions in pcolor/pcolormesh)
@lucaznch lucaznch deleted the docs-pcolor-pcolormesh branch June 6, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants