{"record":{"id":"9facbdfd83a03c87","repo":"matplotlib/matplotlib","slug":"coords-r-is-not-a-valid-coordinate","errorCode":null,"errorMessage":"{coords!r} is not a valid coordinate","messagePattern":"(.+?) is not a valid coordinate","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/text.py","lineNumber":1783,"sourceCode":"        elif isinstance(coords, BboxBase):\n            return BboxTransformTo(coords)\n        elif isinstance(coords, Transform):\n            return coords\n        elif not isinstance(coords, str):\n            raise TypeError(\n                f\"'xycoords' must be an instance of str, tuple[str, str], Artist, \"\n                f\"Transform, or Callable, not a {type(coords).__name__}\")\n\n        if coords == 'data':\n            return self.axes.transData\n        elif coords == 'polar':\n            from matplotlib.projections import PolarAxes\n            return PolarAxes.PolarTransform() + self.axes.transData\n\n        try:\n            bbox_name, unit = coords.split()\n        except ValueError:  # i.e. len(coords.split()) != 2.\n            raise ValueError(f\"{coords!r} is not a valid coordinate\") from None\n\n        bbox0, xy0 = None, None\n\n        # if unit is offset-like\n        if bbox_name == \"figure\":\n            bbox0 = self.get_figure(root=False).figbbox\n        elif bbox_name == \"subfigure\":\n            bbox0 = self.get_figure(root=False).bbox\n        elif bbox_name == \"axes\":\n            bbox0 = self.axes.bbox\n\n        # reference x, y in display coordinate\n        if bbox0 is not None:\n            xy0 = bbox0.p0\n        elif bbox_name == \"offset\":\n            xy0 = self._get_position_xy(renderer)\n        else:\n            raise ValueError(f\"{coords!r} is not a valid coordinate\")","sourceCodeStart":1765,"sourceCodeEnd":1801,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/text.py#L1765-L1801","documentation":"In Annotation._get_xy_transform: string xycoords values other than the bare keywords 'data' and 'polar' must be exactly two whitespace-separated words - a reference-box name plus a unit, like 'axes fraction'. coords.split() must yield two parts; if it yields one (or three), this ValueError is raised.","triggerScenarios":"xycoords='axes' (missing unit); xycoords='figure fraction extra'; typos like 'axes  fraction' are fine (split() handles runs) but 'axesfraction' is one word and fails; a bare unknown keyword like 'screen' also fails here since only 'data' and 'polar' are special-cased.","commonSituations":"Config-driven annotation systems where users type half the spec; porting code that used a single-word spec from another library; forgetting that per-axis tuples must have two-word strings in each slot, e.g. ('axes', 'data') fails on 'axes'.","solutions":["Use complete two-word specs: 'figure points', 'figure pixels', 'figure fraction', 'subfigure ...', 'axes points', 'axes pixels', 'axes fraction', or 'offset <unit>'.","Check typos and concatenations - the string must contain whitespace between the name and the unit.","For per-axis tuples, make each element a valid spec by itself: ('axes fraction', 'data')."],"exampleFix":"# before\nax.annotate('a', xy=(0.5, 0.5), xycoords='axes')  # ValueError\n\n# after\nax.annotate('a', xy=(0.5, 0.5), xycoords='axes fraction')","handlingStrategy":"validation","validationCode":"BOXES = {'figure', 'subfigure', 'axes', 'offset'}\nUNITS = {'points', 'pixels', 'fraction', 'fontsize'}\n\ndef valid_coord_string(c):\n    if c in ('data', 'polar'):\n        return True\n    parts = c.split()\n    return len(parts) == 2 and parts[0] in BOXES and parts[1] in UNITS","typeGuard":null,"tryCatchPattern":null,"preventionTips":["String specs are two words: '<box> <unit>' (e.g. 'axes fraction'), except the bare 'data' and 'polar'.","Validate config-supplied spec strings against the box/unit vocabulary before annotating.","In per-axis tuples, each element must itself be a valid spec."],"tags":["matplotlib","annotation","xycoords","coordinate-system","valueerror"],"backgroundTag":"invalid-coordinate-specifier","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}