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

Skip to content

Commit ba48054

Browse files
committed
Allow passing emtpy list of ticks for FixedLocator
1 parent ff54be0 commit ba48054

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
@@ -1712,7 +1712,9 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
17121712
locator = (self.get_minor_locator() if minor
17131713
else self.get_major_locator())
17141714
if isinstance(locator, mticker.FixedLocator):
1715-
if len(locator.locs) != len(ticklabels):
1715+
# Passing [] as a list of ticklabels is often used as a way to
1716+
# remove all tick labels, so only error for > 0 ticklabels
1717+
if len(locator.locs) != len(ticklabels) and len(ticklabels) != 0:
17161718
raise ValueError(
17171719
"The number of FixedLocator locations"
17181720
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)