Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,9 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
locator = (self.get_minor_locator() if minor
else self.get_major_locator())
if isinstance(locator, mticker.FixedLocator):
if len(locator.locs) != len(ticklabels):
# 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:
raise ValueError(
"The number of FixedLocator locations"
f" ({len(locator.locs)}), usually from a call to"
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4593,6 +4593,14 @@ def test_mismatched_ticklabels():
ax.xaxis.set_ticklabels(['a', 'b', 'c'])


def test_empty_ticks_fixed_loc():
# Smoke test that [] can be used to unset all tick labels
fig, ax = plt.subplots()
ax.bar([1, 2], [1, 2])
ax.set_xticks([1, 2])
ax.set_xticklabels([])


@image_comparison(['retain_tick_visibility.png'])
def test_retain_tick_visibility():
fig, ax = plt.subplots()
Expand Down