{"record":{"id":"2f360b8400b3a2f7","repo":"matplotlib/matplotlib","slug":"incompatible-x-y-inputs-to-funcname-see-help","errorCode":null,"errorMessage":"Incompatible X, Y inputs to {funcname}; see help({funcname})","messagePattern":"Incompatible X, Y inputs to (.+?); see help\\((.+?)\\)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/axes/_axes.py","lineNumber":6516,"sourceCode":"                if np.ma.is_masked(X) or np.ma.is_masked(Y):\n                    raise ValueError(\n                        'x and y arguments to pcolormesh cannot have '\n                        'non-finite values or be of type '\n                        'numpy.ma.MaskedArray with masked values')\n            nrows, ncols = C.shape[:2]\n        else:\n            raise _api.nargs_error(funcname, takes=\"1 or 3\", given=len(args))\n\n        Nx = X.shape[-1]\n        Ny = Y.shape[0]\n        if X.ndim != 2 or X.shape[0] == 1:\n            x = X.reshape(1, Nx)\n            X = x.repeat(Ny, axis=0)\n        if Y.ndim != 2 or Y.shape[1] == 1:\n            y = Y.reshape(Ny, 1)\n            Y = y.repeat(Nx, axis=1)\n        if X.shape != Y.shape:\n            raise TypeError(f'Incompatible X, Y inputs to {funcname}; '\n                            f'see help({funcname})')\n\n        if shading == 'auto':\n            if ncols == Nx and nrows == Ny:\n                shading = 'nearest'\n            else:\n                shading = 'flat'\n\n        if shading == 'flat':\n            if (Nx, Ny) != (ncols + 1, nrows + 1):\n                raise TypeError(f\"Dimensions of C {C.shape} should\"\n                                f\" be one smaller than X({Nx}) and Y({Ny})\"\n                                f\" while using shading='flat'\"\n                                f\" see help({funcname})\")\n        else:    # ['nearest', 'gouraud']:\n            if (Nx, Ny) != (ncols, nrows):\n                raise TypeError('Dimensions of C %s are incompatible with'\n                                ' X (%d) and/or Y (%d); see help(%s)' % (","sourceCodeStart":6498,"sourceCodeEnd":6534,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/axes/_axes.py#L6498-L6534","documentation":"_pcolorargs (shared by pcolor/pcolormesh) broadcasts 1-D inputs to 2-D: X is repeated along rows to (Ny, Nx), Y along columns. After broadcasting, X.shape must equal Y.shape; a mismatch raises this TypeError pointing at help(funcname).","triggerScenarios":"2-D X of shape (Ny1, Nx) paired with 1-D y of length Ny2 != Ny1; X transposed to (Nx, Ny) relative to Y; X and Y taken from two different grids after regridding.","commonSituations":"np.meshgrid misuse (using only one output, or mixing sparse/dense); an old X grid kept with a new Y vector after a resolution change; assuming square grids make shape bugs invisible.","solutions":["Generate both together: X, Y = np.meshgrid(x_1d, y_1d) - or just pass the 1-D vectors: ax.pcolormesh(x_1d, y_1d, C).","Check X.shape == Y.shape right before plotting and transpose one (X = X.T) if a single axis is swapped.","Remember the convention: X.shape[-1] is Nx (columns), Y.shape[0] is Ny (rows)."],"exampleFix":"// before\nX = np.meshgrid(xs, ys)[0]  # (Ny, Nx)\nY = other_ys               # wrong length\nax.pcolormesh(X, Y, C)\n\n// after\nX, Y = np.meshgrid(xs, ys)\nax.pcolormesh(X, Y, C)  # or ax.pcolormesh(xs, ys, C)","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef xy_compatible(X, Y):\n    X, Y = np.asarray(X), np.asarray(Y)\n    Nx, Ny = X.shape[-1], Y.shape[0]\n    Xb = (np.repeat(X.reshape(1, Nx), Ny, axis=0)\n          if (X.ndim != 2 or X.shape[0] == 1) else X)\n    Yb = (np.repeat(Y.reshape(Ny, 1), Nx, axis=1)\n          if (Y.ndim != 2 or Y.shape[1] == 1) else Y)\n    return Xb.shape == Yb.shape\n\n# usage: assert xy_compatible(X, Y) before pcolormesh/pcolor","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create X and Y from the same np.meshgrid call.","Pass 1-D vectors (pcolormesh(x, y, C)) unless a warped grid requires 2-D.","Assert X.shape == Y.shape in grid-loading code."],"tags":["matplotlib","pcolormesh","pcolor","meshgrid","array-shape"],"backgroundTag":"array-shape-mismatch","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}