{"record":{"id":"422316aea12013d5","repo":"matplotlib/matplotlib","slug":"head-width-must-be-nonnegative","errorCode":null,"errorMessage":"'head_width' must be nonnegative","messagePattern":"'head_width' must be nonnegative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/patches.py","lineNumber":2585,"sourceCode":"        \"\"\"A box in the shape of a right-pointing arrow.\"\"\"\n\n        def __init__(self, pad=0.3, head_width=1.5, head_angle=90):\n            \"\"\"\n            Parameters\n            ----------\n            pad : float, default: 0.3\n                The amount of padding around the original box.\n            head_width : float, default: 1.5\n                The head width, relative to the arrow shaft width; must be\n                nonnegative.\n            head_angle : float, default: 90\n                The angle at the tip of the arrow, in degrees; must be nonzero\n                (modulo 360).  Negative angles result in arrow heads pointing\n                backwards.\n            \"\"\"\n            self.pad = pad\n            if head_width < 0:\n                raise ValueError(\"'head_width' must be nonnegative\")\n            self.head_width = head_width\n            if head_angle % 360 == 0:\n                raise ValueError(\"'head_angle' must be nonzero\")\n            self.head_angle = head_angle\n\n        def __call__(self, x0, y0, width, height, mutation_size):\n            # padding & padded dimensions\n            pad = mutation_size * self.pad\n            dx, dy = width + 2 * pad, height + 2 * pad\n            x0, y0 = x0 - pad, y0 - pad,\n            x1, y1 = x0 + dx, y0 + dy\n\n            head_dy = self.head_width * dy\n            mid_y = (y0 + y1) / 2\n            shaft_y0 = mid_y - head_dy / 2\n            shaft_y1 = mid_y + head_dy / 2\n\n            cot = 1 / math.tan(math.radians(self.head_angle / 2))","sourceCodeStart":2567,"sourceCodeEnd":2603,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/patches.py#L2567-L2603","documentation":"The 'rarrow' box style (BoxStyle.RArrow, used by FancyBboxPatch) draws a right-pointing arrow whose head width is head_width times the shaft width. A negative head width would produce inverted, invalid geometry, so the constructor rejects head_width < 0 immediately. Zero is allowed and yields a headless flat right edge.","triggerScenarios":"BoxStyle.RArrow(head_width=-1); FancyBboxPatch(boxstyle='rarrow,head_width=-0.5'); a config-driven head_width whose sign is computed (e.g. head_width=-w instead of abs(w)).","commonSituations":"Sign errors from arithmetic on user config; parsing a value with a stray minus from a config file or CLI; unit-test fixtures sweeping negative values.","solutions":["Use a nonnegative value; the default is 1.5 (relative to the arrow shaft width)","Clamp config input: head_width=abs(float(cfg.get('head_width', 1.5)))","Use head_width=0 if you want the arrow shape without a widened head"],"exampleFix":"// before\nbox = FancyBboxPatch((0, 0), 1, 1, boxstyle=f'rarrow,head_width={w}')  # w = -0.5\n// after\nbox = FancyBboxPatch((0, 0), 1, 1, boxstyle=f'rarrow,head_width={abs(w)}')","handlingStrategy":"validation","validationCode":"head_width = float(cfg.get('head_width', 1.5))\nif head_width < 0:\n    head_width = abs(head_width)  # or raise for strict config validation\nbox = FancyBboxPatch((0, 0), 1, 1, boxstyle='rarrow', head_width=head_width)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate numeric config at load time: reject or abs() negative dimension-like values","Keep in mind head_width is relative to the shaft width, default 1.5"],"tags":["matplotlib","boxstyle","rarrow","fancybboxpatch","argument-validation"],"backgroundTag":"out-of-range-parameter","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}