Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5748,9 +5748,9 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):

if shading == 'flat':
if (Nx, Ny) != (ncols + 1, nrows + 1):
raise TypeError('Dimensions of C %s are incompatible with'
' X (%d) and/or Y (%d); see help(%s)' % (
C.shape, Nx, Ny, funcname))
raise TypeError(f"Dimensions of X({Nx}) and y({Ny}) should"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y should be capitalized. Suggest "Relevant" because X and Y can be 2-D.... Otherwise this looks good to me...

Suggested change
raise TypeError(f"Dimensions of X({Nx}) and y({Ny}) should"
raise TypeError(f"Relevant dimensions of X({Nx}) and Y({Ny}) should"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok Sir, Thank you for the suggestion

f"be one larger than C{C.shape}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error should probably say something about shading='flat', because it is possible to pass x and y the same shape as C for shading='auto' and shading='nearest'. See https://matplotlib.org/stable/gallery/images_contours_and_fields/pcolormesh_grids.html for a discussion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jklymak Sir, Updated the error message

f"see help({funcname})")
else: # ['nearest', 'gouraud']:
if (Nx, Ny) != (ncols, nrows):
raise TypeError('Dimensions of C %s are incompatible with'
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,14 @@ def test_pcolorflaterror():
ax.pcolormesh(x, y, Z, shading='flat')


def test_samesizepcolorflaterror():
fig, ax = plt.subplots()
x, y = np.meshgrid(np.arange(5), np.arange(3))
Z = x + y
with pytest.raises(TypeError, match=r".*one larger than C"):
ax.pcolormesh(x, y, Z, shading='flat')


@pytest.mark.parametrize('snap', [False, True])
@check_figures_equal(extensions=["png"])
def test_pcolorauto(fig_test, fig_ref, snap):
Expand Down