{"record":{"id":"570393708c002a56","repo":"matplotlib/matplotlib","slug":"for-a-bivarcolormap-the-data-must-have-a-first-d","errorCode":null,"errorMessage":"For a `BivarColormap` the data must have a first dimension 2, not {len(X)}","messagePattern":"For a `BivarColormap` the data must have a first dimension 2, not (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/colors.py","lineNumber":1766,"sourceCode":"            - For integers, *X* should be in the interval ``[0, Colormap.N)`` to\n              return RGBA values *indexed* from the Colormap with index ``X``.\n\n        alpha : float or array-like or None, default: None\n            Alpha must be a scalar between 0 and 1, a sequence of such\n            floats with shape matching X0, or None.\n        bytes : bool, default: False\n            If False (default), the returned RGBA values will be floats in the\n            interval ``[0, 1]`` otherwise they will be `numpy.uint8`\\s in the\n            interval ``[0, 255]``.\n\n        Returns\n        -------\n        Tuple of RGBA values if X is scalar, otherwise an array of\n        RGBA values with a shape of ``X.shape + (4, )``.\n        \"\"\"\n\n        if len(X) != 2:\n            raise ValueError(\n                f'For a `BivarColormap` the data must have a first dimension '\n                f'2, not {len(X)}')\n\n        if not self._isinit:\n            self._init()\n\n        X0 = np.ma.array(X[0], copy=True)\n        X1 = np.ma.array(X[1], copy=True)\n        # clip to shape of colormap, circle square, etc.\n        self._clip((X0, X1))\n\n        # Native byteorder is faster.\n        if not X0.dtype.isnative:\n            X0 = X0.byteswap().view(X0.dtype.newbyteorder())\n        if not X1.dtype.isnative:\n            X1 = X1.byteswap().view(X1.dtype.newbyteorder())\n\n        if X0.dtype.kind == \"f\":","sourceCodeStart":1748,"sourceCodeEnd":1784,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/colors.py#L1748-L1784","documentation":"BivarColormap maps exactly two data arrays: X must be a sequence with first dimension 2 (for example [X0, X1]). Any other first-dimension length is rejected before the normalization and color mixing run.","triggerScenarios":"bivar_cmap(X0) with the list wrapper missing; bivar_cmap([X0, X1, X2]) with three arrays; passing a channels-last stack (H, W, 2) whose first dimension is H.","commonSituations":"Feeding an array stacked for another imaging API that puts channels last; leftover code written for 3+ variates; forgetting the list wrapper when both variates come from one variable.","solutions":["Pass two arrays: rgba = bivar_cmap([X0, X1]).","If the data is a stacked array, make its shape (2, ...) first: np.stack([X0, X1]) or transpose as needed.","For three or more variates, use MultivarColormap instead of BivarColormap."],"exampleFix":"// before\nrgba = bivar_cmap(X0)  # only one array\n// after\nrgba = bivar_cmap([X0, X1])","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef conform_bivar(X):\n    if np.asarray(X).shape[0] != 2:\n        raise ValueError(\n            'BivarColormap needs exactly 2 data arrays, e.g. [X0, X1]')\n    return X","typeGuard":null,"tryCatchPattern":"try:\n    rgba = bivar_cmap(X)\nexcept ValueError as e:\n    if 'first dimension 2' in str(e):\n        raise ValueError('pass [X0, X1] to BivarColormap') from e\n    raise","preventionTips":["Wrap the two variates in a list at the call site.","Keep bivariate data stacks in (2, H, W) shape.","Use MultivarColormap for more than two variates."],"tags":["matplotlib","bivar-colormap","dimension-mismatch"],"backgroundTag":"data-dimension-mismatch","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}