{"record":{"id":"bc3c89b0ef529df5","repo":"matplotlib/matplotlib","slug":"triangles-are-indices-into-the-points-and-must-be","errorCode":null,"errorMessage":"triangles are indices into the points and must be in the range 0 <= i < {len(self.x)} but found value {self.triangles.max()}","messagePattern":"triangles are indices into the points and must be in the range 0 <= i < (.+?) but found value (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/tri/_triangulation.py","lineNumber":75,"sourceCode":"        if triangles is None:\n            # No triangulation specified, so use matplotlib._qhull to obtain\n            # Delaunay triangulation.\n            self.triangles, self._neighbors = _qhull.delaunay(x, y, sys.flags.verbose)\n            self.is_delaunay = True\n        else:\n            # Triangulation specified. Copy, since we may correct triangle\n            # orientation.\n            try:\n                self.triangles = np.array(triangles, dtype=np.int32, order='C')\n            except ValueError as e:\n                raise ValueError('triangles must be a (N, 3) int array, not '\n                                 f'{triangles!r}') from e\n            if self.triangles.ndim != 2 or self.triangles.shape[1] != 3:\n                raise ValueError(\n                    'triangles must be a (N, 3) int array, but found shape '\n                    f'{self.triangles.shape!r}')\n            if self.triangles.max() >= len(self.x):\n                raise ValueError(\n                    'triangles are indices into the points and must be in the '\n                    f'range 0 <= i < {len(self.x)} but found value '\n                    f'{self.triangles.max()}')\n            if self.triangles.min() < 0:\n                raise ValueError(\n                    'triangles are indices into the points and must be in the '\n                    f'range 0 <= i < {len(self.x)} but found value '\n                    f'{self.triangles.min()}')\n\n        # Underlying C++ object is not created until first needed.\n        self._cpp_triangulation = None\n\n        # Default TriFinder not created until needed.\n        self._trifinder = None\n\n        self.set_mask(mask)\n\n    def calculate_plane_coefficients(self, z):","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/tri/_triangulation.py#L57-L93","documentation":"Error \"triangles are indices into the points and must be in the range 0 <= i < {len(self.x)} but found value {self.triangles.max()}\" thrown in matplotlib/matplotlib.","triggerScenarios":"Thrown at lib/matplotlib/tri/_triangulation.py:75 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}