{"record":{"id":"4ab0ddce23e0b5f5","repo":"matplotlib/matplotlib","slug":"x-must-be-a-sequence","errorCode":null,"errorMessage":"x must be a sequence","messagePattern":"x must be a sequence","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/lines.py","lineNumber":1339,"sourceCode":"        if self._markersize != sz:\n            self.stale = True\n        self._markersize = sz\n\n    def set_xdata(self, x):\n        \"\"\"\n        Set the data array for x.\n\n        Parameters\n        ----------\n        x : 1D array\n\n        See Also\n        --------\n        set_data\n        set_ydata\n        \"\"\"\n        if not np.iterable(x):\n            raise RuntimeError('x must be a sequence')\n        self._xorig = copy.copy(x)\n        self._invalidx = True\n        self.stale = True\n\n    def set_ydata(self, y):\n        \"\"\"\n        Set the data array for y.\n\n        Parameters\n        ----------\n        y : 1D array\n\n        See Also\n        --------\n        set_data\n        set_xdata\n        \"\"\"\n        if not np.iterable(y):","sourceCodeStart":1321,"sourceCodeEnd":1357,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/lines.py#L1321-L1357","documentation":"Line2D.set_xdata stores the x data and requires it to be iterable; np.iterable(x) returned False, so a scalar was passed. Unlike the higher-level plotting APIs there is no coercion here: the value is copied into _xorig as-is and must already be a sequence.","triggerScenarios":"line.set_xdata(5); line.set_xdata(np.float64(2.5)); line.set_xdata(None) when trying to clear the line.","commonSituations":"Live-update/animation code assigning a freshly computed scalar (for example a rolling last value) instead of a length-1 array; replacing arrays with None to 'clear' a line instead of using set_data([], []).","solutions":["Wrap scalars in a list: line.set_xdata([5])","To clear a line use empty sequences: line.set_data([], [])","Keep a buffer array and assign the buffer or slices of it, never scalar reductions of it"],"exampleFix":"# before\nline.set_xdata(new_x_value)\n# after\nline.set_xdata([new_x_value])","handlingStrategy":"type-guard","validationCode":"import numpy as np\nif not np.iterable(x):\n    x = [x]\nline.set_xdata(x)","typeGuard":"import numpy as np\n\ndef is_sequence(v) -> bool:\n    return np.iterable(v) and not isinstance(v, (str, bytes))","tryCatchPattern":null,"preventionTips":["In update loops always assign sequences (lists or arrays), never loop scalars","Use line.set_data([], []) to clear data instead of None"],"tags":["matplotlib","lines","data-update","sequence"],"backgroundTag":"argument-not-iterable","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}