{"record":{"id":"8e6a3ccbf179375c","repo":"matplotlib/matplotlib","slug":"invalid-arguments-to-set-clip-path-of-type-type","errorCode":null,"errorMessage":"Invalid arguments to set_clip_path, of type {type(path).__name__} and {type(transform).__name__}","messagePattern":"Invalid arguments to set_clip_path, of type (.+?) and (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/artist.py","lineNumber":881,"sourceCode":"                success = True\n            elif isinstance(path, tuple):\n                path, transform = path\n\n        if path is None:\n            self._clippath = None\n            success = True\n        elif isinstance(path, Path):\n            self._clippath = TransformedPath(path, transform)\n            success = True\n        elif isinstance(path, TransformedPatchPath):\n            self._clippath = path\n            success = True\n        elif isinstance(path, TransformedPath):\n            self._clippath = path\n            success = True\n\n        if not success:\n            raise TypeError(\n                \"Invalid arguments to set_clip_path, of type \"\n                f\"{type(path).__name__} and {type(transform).__name__}\")\n        # This may result in the callbacks being hit twice, but guarantees they\n        # will be hit at least once.\n        self.pchanged()\n        self.stale = True\n\n    def get_alpha(self):\n        \"\"\"\n        Return the alpha value used for blending - not supported on all\n        backends.\n        \"\"\"\n        return self._alpha\n\n    def get_visible(self):\n        \"\"\"Return the visibility.\"\"\"\n        return self._visible\n","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/artist.py#L863-L899","documentation":"set_clip_path accepts exactly four shapes: a Patch (optionally with a Transform), a Path plus a Transform, a TransformedPatchPath, or a TransformedPath. Anything else - list/tuple of vertices, ndarray, Bbox, string - leaves the success flag unset and raises TypeError 'Invalid arguments to set_clip_path, of type {path} and {transform}'.","triggerScenarios":"artist.set_clip_path([(0, 0), (1, 0), (1, 1)]) with raw vertices; passing a matplotlib.transforms.Bbox (that is set_clip_box's job); passing a Path but forgetting the second transform argument in code paths that require it; passing a clip rectangle created by another library.","commonSituations":"Clipping images/heatmaps to country or region outlines (vertices come from geo packages as arrays); porting code from other plotting libs where clip paths are plain point lists; quick rectangle clips where Bbox would be simpler.","solutions":["Wrap vertices: from matplotlib.path import Path; artist.set_clip_path(Path(verts), transform=ax.transAxes) (or the relevant data transform)","For rectangle clips use set_clip_box(mpl.transforms.Bbox([[x0, y0], [x1, y1]]))","Pass a Patch (e.g. Circle, Polygon) directly - it carries its own transform: artist.set_clip_path(Circle((0, 0), 1, transform=ax.transData))","Reuse existing transformed paths (artist.get_clip_path()) when re-applying"],"exampleFix":"# before\nverts = [(0, 0), (1, 0), (1, 1), (0, 0)]\nim.set_clip_path(verts)  # TypeError: list is not a valid clip path\n\n# after\nfrom matplotlib.path import Path\nim.set_clip_path(Path(verts), transform=ax.transAxes)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from matplotlib.path import Path\nfrom matplotlib.patches import Patch\nfrom matplotlib.transforms import Transform, TransformedPath\n\ndef is_valid_clip_args(path, transform=None):\n    if isinstance(path, (Patch, TransformedPath)):\n        return True\n    return isinstance(path, Path) and isinstance(transform, Transform)","tryCatchPattern":null,"preventionTips":["Convert raw vertices to Path(verts) and always pass an explicit transform (ax.transData / ax.transAxes)","Use set_clip_box(Bbox(...)) for rectangle clips","Pass Patch objects straight through - they carry their own transforms"],"tags":["artist","clip-path","path","transform","invalid-type"],"backgroundTag":"invalid-argument-type","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}