From 2852d46b65f65352f6b7c24e8b108e41d42e7e52 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 28 Oct 2021 14:11:33 +0200 Subject: [PATCH 1/2] FIX: fix logic for FixedLocator set_ticklabels --- lib/matplotlib/axis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index bfdb62df8377..eaed442f03d0 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1706,10 +1706,10 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): if isinstance(locator, mticker.FixedLocator): # Passing [] as a list of ticklabels is often used as a way to # remove all tick labels, so only error for > 0 ticklabels - if len(locator.locs) != len(ticklabels) and len(ticklabels) != 0: + if locator.nbins - 1 != len(ticklabels) and len(ticklabels) != 0: raise ValueError( "The number of FixedLocator locations" - f" ({len(locator.locs)}), usually from a call to" + f" ({locator.nbins}), usually from a call to" " set_ticks, does not match" f" the number of ticklabels ({len(ticklabels)}).") tickd = {loc: lab for loc, lab in zip(locator.locs, ticklabels)} From f17d84a47431c4fb4476eed782220a1ae353b8f1 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 28 Oct 2021 15:16:37 +0200 Subject: [PATCH 2/2] FIX: fix logic for FixedLocator set_ticklabels --- lib/matplotlib/axis.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index eaed442f03d0..01e6e733c1f1 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1706,10 +1706,12 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs): if isinstance(locator, mticker.FixedLocator): # Passing [] as a list of ticklabels is often used as a way to # remove all tick labels, so only error for > 0 ticklabels - if locator.nbins - 1 != len(ticklabels) and len(ticklabels) != 0: + nticks = (locator.nbins if locator.nbins is not None + else len(locator.locs)) + if nticks != len(ticklabels) and len(ticklabels) != 0: raise ValueError( "The number of FixedLocator locations" - f" ({locator.nbins}), usually from a call to" + f" ({nticks}), usually from a call to" " set_ticks, does not match" f" the number of ticklabels ({len(ticklabels)}).") tickd = {loc: lab for loc, lab in zip(locator.locs, ticklabels)}