Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5645021

Browse files
authored
Merge pull request #17787 from meeseeksmachine/auto-backport-of-pr-17784-on-v3.3.x
Backport PR #17784 on branch v3.3.x (Allow passing emtpy list of ticks to FixedLocator)
2 parents 8186be0 + 9ec9725 commit 5645021

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/axis.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,9 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
17081708
locator = (self.get_minor_locator() if minor
17091709
else self.get_major_locator())
17101710
if isinstance(locator, mticker.FixedLocator):
1711-
if len(locator.locs) != len(ticklabels):
1711+
# Passing [] as a list of ticklabels is often used as a way to
1712+
# remove all tick labels, so only error for > 0 ticklabels
1713+
if len(locator.locs) != len(ticklabels) and len(ticklabels) != 0:
17121714
raise ValueError(
17131715
"The number of FixedLocator locations"
17141716
f" ({len(locator.locs)}), usually from a call to"

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,6 +4593,14 @@ def test_mismatched_ticklabels():
45934593
ax.xaxis.set_ticklabels(['a', 'b', 'c'])
45944594

45954595

4596+
def test_empty_ticks_fixed_loc():
4597+
# Smoke test that [] can be used to unset all tick labels
4598+
fig, ax = plt.subplots()
4599+
ax.bar([1, 2], [1, 2])
4600+
ax.set_xticks([1, 2])
4601+
ax.set_xticklabels([])
4602+
4603+
45964604
@image_comparison(['retain_tick_visibility.png'])
45974605
def test_retain_tick_visibility():
45984606
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)