{"record":{"id":"b61b64fd56c3b0a4","repo":"matplotlib/matplotlib","slug":"invalid-vmin-or-vmax","errorCode":null,"errorMessage":"Invalid vmin or vmax","messagePattern":"Invalid vmin or vmax","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/colors.py","lineNumber":2957,"sourceCode":"            inspect.Parameter(\"self\", inspect.Parameter.POSITIONAL_OR_KEYWORD),\n            *bound_init_signature.parameters.values()])\n\n        def __call__(self, value, clip=None):\n            value, is_scalar = self.process_value(value)\n            if self.vmin is None or self.vmax is None:\n                self.autoscale_None(value)\n            if self.vmin > self.vmax:\n                raise ValueError(\"vmin must be less or equal to vmax\")\n            if self.vmin == self.vmax:\n                return np.full_like(value, 0)\n            if clip is None:\n                clip = self.clip\n            if clip:\n                value = np.clip(value, self.vmin, self.vmax)\n            t_value = self._trf.transform(value).reshape(np.shape(value))\n            t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])\n            if not np.isfinite([t_vmin, t_vmax]).all():\n                raise ValueError(\"Invalid vmin or vmax\")\n            t_value -= t_vmin\n            t_value /= (t_vmax - t_vmin)\n            t_value = np.ma.masked_invalid(t_value, copy=False)\n            return t_value[0] if is_scalar else t_value\n\n        def inverse(self, value):\n            if not self.scaled():\n                raise ValueError(\"Not invertible until scaled\")\n            if self.vmin > self.vmax:\n                raise ValueError(\"vmin must be less or equal to vmax\")\n            t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])\n            if not np.isfinite([t_vmin, t_vmax]).all():\n                raise ValueError(\"Invalid vmin or vmax\")\n            value, is_scalar = self.process_value(value)\n            rescaled = value * (t_vmax - t_vmin)\n            rescaled += t_vmin\n            value = (self._trf\n                     .inverted()","sourceCodeStart":2939,"sourceCodeEnd":2975,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/colors.py#L2939-L2975","documentation":"For scale-backed norms (LogNorm, AsinhNorm, FuncNorm), __call__ transforms [vmin, vmax] through the scale and requires both results to be finite. With a log scale, a vmin or vmax <= 0 transforms to NaN/masked and raises 'Invalid vmin or vmax'. Data values outside the domain are only masked; it is the limits themselves that must be valid.","triggerScenarios":"LogNorm(vmin=0, vmax=100)(data); LogNorm(vmin=-5, vmax=5); pinning vmax=0 for all-negative data; FuncNorm whose inverse is undefined at the chosen limits.","commonSituations":"Log-scaling datasets bounded by zero (copying linear-norm limits into log plots); choropleth/count data where 0 was the old vmin; defaults that insert 0 as the lower bound.","solutions":["Use strictly positive limits: vmin = max(vmin, smallest_positive_value)","For zero-crossing data use SymLogNorm(linthresh=...) or AsinhNorm instead of LogNorm","Let autoscale derive limits from the positive values rather than pinning vmin=0"],"exampleFix":"# before\nnorm = LogNorm(vmin=0, vmax=100)      # ValueError\n\n# after\nnorm = LogNorm(vmin=1e-3, vmax=100)\n# or for data crossing zero:\nnorm = SymLogNorm(linthresh=1e-3, vmin=-100, vmax=100)","handlingStrategy":"validation","validationCode":"if norm.__class__.__name__ == 'LogNorm' and (vmin <= 0 or vmax <= 0):\n    raise ValueError(f'LogNorm limits must be positive; got vmin={vmin}, vmax={vmax}')\nnormed = norm(data)","typeGuard":"def lognorm_range_ok(vmin, vmax) -> bool:\n    return vmin > 0 and vmax > 0 and vmin <= vmax","tryCatchPattern":"try:\n    normed = norm(data)\nexcept ValueError as e:\n    if 'Invalid vmin or vmax' in str(e) and isinstance(norm, LogNorm):\n        norm = SymLogNorm(linthresh=max(vmin, 1e-3), vmin=vmin, vmax=vmax)\n        normed = norm(data)\n    else:\n        raise","preventionTips":["Never pin vmin=0 on log scales; clamp to the smallest positive value","Use SymLogNorm or AsinhNorm for data that includes or crosses zero","Validate positivity where the norm is built so both __call__ and inverse are safe"],"tags":["matplotlib","lognorm","vmin-vmax","nonpositive","nan"],"backgroundTag":"lognorm-nonpositive-range","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}