{"record":{"id":"cbf36bf8e2e2efff","repo":"matplotlib/matplotlib","slug":"name-r-is-not-1-dimensional","errorCode":null,"errorMessage":"{name!r} is not 1-dimensional","messagePattern":"(.+?) is not 1-dimensional","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/collections.py","lineNumber":1561,"sourceCode":"        \"\"\"\n        if where is None:\n            where = True\n        else:\n            where = np.asarray(where, dtype=bool)\n            if where.size != t.size:\n                msg = \"where size ({}) does not match {!r} size ({})\".format(\n                    where.size, self.t_direction, t.size)\n                raise ValueError(msg)\n        return where & ~functools.reduce(\n            np.logical_or, map(np.ma.getmaskarray, [t, f1, f2]))\n\n    @staticmethod\n    def _validate_shapes(t_dir, f_dir, t, f1, f2):\n        \"\"\"Validate that t, f1 and f2 are 1-dimensional and have the same length.\"\"\"\n        names = (d + s for d, s in zip((t_dir, f_dir, f_dir), (\"\", \"1\", \"2\")))\n        for name, array in zip(names, [t, f1, f2]):\n            if array.ndim > 1:\n                raise ValueError(f\"{name!r} is not 1-dimensional\")\n            if t.size > 1 and array.size > 1 and t.size != array.size:\n                msg = \"{!r} has size {}, but {!r} has an unequal size of {}\".format(\n                    t_dir, t.size, name, array.size)\n                raise ValueError(msg)\n\n    def _make_verts_for_region(self, t, f1, f2, idx0, idx1):\n        \"\"\"\n        Make ``verts`` for a contiguous region between ``idx0`` and ``idx1``, taking\n        into account ``step`` and ``interpolate``.\n        \"\"\"\n        t_slice = t[idx0:idx1]\n        f1_slice = f1[idx0:idx1]\n        f2_slice = f2[idx0:idx1]\n        if self._step is not None:\n            step_func = cbook.STEP_LOOKUP_MAP[\"steps-\" + self._step]\n            t_slice, f1_slice, f2_slice = step_func(t_slice, f1_slice, f2_slice)\n\n        if self._interpolate:","sourceCodeStart":1543,"sourceCodeEnd":1579,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/collections.py#L1543-L1579","documentation":"FillBetweenPolyCollection._validate_shapes requires t, f1 and f2 to be 1-dimensional; any input with ndim > 1 raises ValueError naming the offending argument ('x', 'y1'/'x1', 'y2'/'x2' depending on direction). fill_between is a curve API — gridded data belongs to pcolormesh/imshow.","triggerScenarios":"ax.fill_between(X, Y1, Y2) with 2D meshgrid-style arrays; passing (N,1) column vectors (e.g. df[['col']].to_numpy()); slicing matrix columns without raveling.","commonSituations":"Reusing gridded model output in fill_between; pandas column selection with double brackets producing 2D arrays; broadcasting habits carried over from NumPy where they do not apply.","solutions":["Ravel all inputs: ax.fill_between(x.ravel(), y1.ravel(), y2.ravel())","Select pandas columns as 1D: df['a'].to_numpy(), not df[['a']].to_numpy()","For genuinely 2D fields use pcolormesh/contourf instead of fill_between"],"exampleFix":"# before\nax.fill_between(x[:, None], y1, y2)  # x shaped (N, 1) -> 2D\n\n# after\nax.fill_between(x.ravel(), y1.ravel(), y2.ravel())","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef as_1d(name, a):\n    a = np.asarray(a)\n    if a.ndim != 1:\n        raise ValueError(f'{name} must be 1D, got ndim={a.ndim}')\n    return a\n\nax.fill_between(as_1d('x', x), as_1d('y1', y1), as_1d('y2', y2))","typeGuard":"import numpy as np\n\ndef is_1d(a) -> bool:\n    return np.ndim(a) == 1","tryCatchPattern":null,"preventionTips":["ravel() column vectors before plotting","Use df['col'] (1D), not df[['col']] (2D), when extracting pandas series","Reserve fill_between for 1D curve data; gridded data goes to pcolormesh"],"tags":["matplotlib","fill-between","dimensionality","shape-validation","valueerror"],"backgroundTag":"array-dimensionality-mismatch","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}