{"record":{"id":"f752882d8adc949b","repo":"matplotlib/matplotlib","slug":"cannot-pass-both-positional-and-keyword-arguments","errorCode":null,"errorMessage":"Cannot pass both positional and keyword arguments for x and/or y.","messagePattern":"Cannot pass both positional and keyword arguments for x and/or y\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/axes/_base.py","lineNumber":2923,"sourceCode":"        -------\n        xmargin, ymargin : float\n\n        Notes\n        -----\n        If a previously used Axes method such as :meth:`pcolor` has set\n        `~.Axes.use_sticky_edges` to `True`, only the limits not set by\n        the \"sticky artists\" will be modified. To force all\n        margins to be set, set `~.Axes.use_sticky_edges` to `False`\n        before calling :meth:`margins`.\n\n        See Also\n        --------\n        :ref:`autoscale_margins`\n        .Axes.set_xmargin, .Axes.set_ymargin\n        \"\"\"\n\n        if margins and (x is not None or y is not None):\n            raise TypeError('Cannot pass both positional and keyword '\n                            'arguments for x and/or y.')\n        elif len(margins) == 1:\n            x = y = margins[0]\n        elif len(margins) == 2:\n            x, y = margins\n        elif margins:\n            raise TypeError('Must pass a single positional argument for all '\n                            'margins, or one for each margin (x, y).')\n\n        if x is None and y is None:\n            if tight is not True:\n                _api.warn_external(f'ignoring tight={tight!r} in get mode')\n            return self._xmargin, self._ymargin\n\n        if tight is not None:\n            self._tight = tight\n        if x is not None:\n            self.set_xmargin(x)","sourceCodeStart":2905,"sourceCodeEnd":2941,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/axes/_base.py#L2905-L2941","documentation":"Axes.margins() accepts margins either positionally (one value for all axes, or one value per axis) or through the x=/y= keyword arguments, but not both at once. Supplying positional margins together with x or y is ambiguous about which value wins, so matplotlib raises this TypeError before touching any state.","triggerScenarios":"ax.margins(0.2, x=0.1); ax.margins(0.1, 0.2, y=0.3); wrapper functions that forward *args while also injecting explicit x=/y= keywords.","commonSituations":"Incrementally editing an existing positional call by appending keyword overrides; generic plotting helpers that merge user kwargs with their own margins settings; copy-paste between the two calling conventions.","solutions":["Choose one convention: drop the keyword arguments and pass all values positionally, or drop the positional values and pass x=/y= only.","For partial updates, use the keyword form only, e.g. ax.margins(x=0.1) leaves y untouched.","In wrappers, pop or merge margins before forwarding a single canonical form."],"exampleFix":"# before\nax.margins(0.2, x=0.1)\n\n# after\nax.margins(x=0.1)","handlingStrategy":"validation","validationCode":"if pos_margins and (x is not None or y is not None):\n    pos_margins = ()  # let keywords win, or raise your own error\nax.margins(*pos_margins, x=x, y=y)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one calling convention (positional or keyword) per call site and stick to it.","In wrappers, resolve margins into a single canonical form (x=, y=) before delegating."],"tags":["matplotlib","margins","api-misuse","conflicting-arguments"],"backgroundTag":"conflicting-arguments","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}