matplotlib/matplotlib · error · ValueError

The number of FixedLocator locations ({len(fixed_locator.loc

Error message

The number of FixedLocator locations ({len(fixed_locator.locs)}), usually from a call to set_ticks, does not match the number of labels ({len(labels)}).

What it means

Error "The number of FixedLocator locations ({len(fixed_locator.locs)}), usually from a call to set_ticks, does not match the number of labels ({len(labels)})." thrown in matplotlib/matplotlib.

Source

Thrown at lib/matplotlib/axis.py:2340

        try:
            labels = [t.get_text() if hasattr(t, 'get_text') else t
                      for t in labels]
        except TypeError:
            raise TypeError(f"{labels=!r} must be a sequence") from None
        locator = (self.get_minor_locator() if minor
                   else self.get_major_locator())
        if not labels:
            formatter = mticker.NullFormatter()
        elif (isinstance(locator, mticker.FixedLocator) or
              (hasattr(locator, 'base') and
               isinstance(locator.base, mticker.FixedLocator))):
            # Also handles locators that wrap a FixedLocator (e.g. RadialLocator).
            fixed_locator = (locator if isinstance(locator, mticker.FixedLocator)
                             else locator.base)
            # Passing [] as a list of labels is often used as a way to
            # remove all tick labels, so only error for > 0 labels
            if len(fixed_locator.locs) != len(labels) and len(labels) != 0:
                raise ValueError(
                    "The number of FixedLocator locations"
                    f" ({len(fixed_locator.locs)}), usually from a call to"
                    " set_ticks, does not match"
                    f" the number of labels ({len(labels)}).")
            tickd = {loc: lab for loc, lab in zip(fixed_locator.locs, labels)}
            func = functools.partial(self._format_with_dict, tickd)
            formatter = mticker.FuncFormatter(func)
        else:
            _api.warn_external(
                 "set_ticklabels() should only be used with a fixed number of "
                 "ticks, i.e. after set_ticks() or using a FixedLocator. "
                 "Otherwise, ticks may be mislabeled.")
            formatter = mticker.FixedFormatter(labels)

        with warnings.catch_warnings():
            warnings.filterwarnings(
                "ignore",
                message="FixedFormatter should only be used together with FixedLocator")

View on GitHub (pinned to b379c1b69e)

When it happens

Trigger: Thrown at lib/matplotlib/axis.py:2340 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21). Data as JSON: /api/errors/970613be8a650800. Report an issue: GitHub.