{"record":{"id":"70fbac298339bdad","repo":"matplotlib/matplotlib","slug":"unknown-type-of-bbox","errorCode":null,"errorMessage":"Unknown type of bbox","messagePattern":"Unknown type of bbox","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/image.py","lineNumber":1529,"sourceCode":"            colorizer=colorizer,\n            interpolation=interpolation,\n            origin=origin,\n            filternorm=filternorm,\n            filterrad=filterrad,\n            resample=resample,\n            **kwargs\n        )\n        self.bbox = bbox\n\n    def get_window_extent(self, renderer=None):\n        if isinstance(self.bbox, BboxBase):\n            return self.bbox\n        elif callable(self.bbox):\n            if renderer is None:\n                renderer = self.get_figure()._get_renderer()\n            return self.bbox(renderer)\n        else:\n            raise ValueError(\"Unknown type of bbox\")\n\n    def contains(self, mouseevent):\n        \"\"\"Test whether the mouse event occurred within the image.\"\"\"\n        if self._different_canvas(mouseevent) or not self.get_visible():\n            return False, {}\n        x, y = mouseevent.x, mouseevent.y\n        inside = self.get_window_extent().contains(x, y)\n        return inside, {}\n\n    def make_image(self, renderer, magnification=1.0, unsampled=False):\n        # docstring inherited\n        width, height = renderer.get_canvas_width_height()\n        bbox_in = self.get_window_extent(renderer).frozen()\n        bbox_in._points /= [width, height]\n        bbox_out = self.get_window_extent(renderer)\n        clip = Bbox([[0, 0], [width, height]])\n        self._transform = BboxTransformTo(clip)\n        return self._make_image(","sourceCodeStart":1511,"sourceCodeEnd":1547,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/image.py#L1511-L1547","documentation":"BboxImage accepts a bbox that is either a BboxBase instance or a callable taking a renderer and returning a Bbox. get_window_extent stores nothing else: any other type (tuple, list, ndarray, string, ...) is only detected when get_window_extent runs — during draw, contains, or pick — and then raises ValueError('Unknown type of bbox').","triggerScenarios":"BboxImage((0, 0, 1, 1), ...) — a plain 4-tuple or nested list passed instead of a Bbox; then fig.canvas.draw() or a mouseover contains() check triggers the error.","commonSituations":"Assuming matplotlib accepts extent-style tuples anywhere an extent is needed; wrapping BboxImage with dynamically computed rectangles but passing a tuple literal; copy-pasted examples using older/other APIs.","solutions":["Wrap the coordinates: BboxImage(Bbox.from_bounds(x, y, w, h), ...) or Bbox([[x0, y0], [x1, y1]]).","For dynamic placement, pass a callable: BboxImage(lambda renderer: compute_bbox(renderer), ...).","Validate up front with isinstance(bbox, BboxBase) or callable(bbox)."],"exampleFix":"# before\nim = BboxImage((0.1, 0.1, 0.9, 0.9), cmap='viridis')  # tuple -> ValueError at draw\n\n# after\nfrom matplotlib.transforms import Bbox\nim = BboxImage(Bbox.from_bounds(0.1, 0.1, 0.8, 0.8), cmap='viridis')","handlingStrategy":"type-guard","validationCode":"from matplotlib.transforms import BboxBase\n\nif not (isinstance(bbox, BboxBase) or callable(bbox)):\n    bbox = Bbox.from_bounds(*bbox)  # accept 4-tuples defensively\nim = BboxImage(bbox, ...)","typeGuard":"from matplotlib.transforms import BboxBase\n\ndef is_valid_bbox_arg(b) -> bool:\n    return isinstance(b, BboxBase) or callable(b)","tryCatchPattern":null,"preventionTips":["Construct Bbox explicitly: Bbox.from_bounds(x, y, w, h) or Bbox([[x0,y0],[x1,y1]]).","Remember the error surfaces at draw time, not construction — validate up front.","Use a callable only when bounds must react to the renderer."],"tags":["matplotlib","bboximage","bbox","type-error","argument-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}