Description
Bug report
Bug summary
#17266 requires tick labels set by FixedFormatter
to be equal to the ticks set by FixedLocator
. FixedLocator
is used in many cases where categorical data is plotted, e.g. bar
and box plot
. A way of removing all tick labels (while maintaining ticks and gridlines) is to do ax.set_xticklabels([])
or ax.set_yticklabels([])
, by passing just an empty list. This works on 3.2.2, but raises a ValueError
with 3.3.0rc1.
The new behavior is not mentioned in the "What's new?" section of 3.3.0rc1. I suspect this may break existing code, as it broke seaborn and this stackoverflow thread seems very popular.
Code for reproduction
# Example modified from bar example page
import matplotlib.pyplot as plt
import numpy as np
labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')
ax.set_xticks(x)
ax.set_xticklabels([])
Actual outcome
# 3.3.0rc1
ValueError: The number of FixedLocator locations (5), usually from a call to set_ticks, does not match the number of ticklabels (0).
Expected outcome
Unset tick labels but not error out, or raise a deprecation warning that this won't be possible in a future release.
Matplotlib version
- Operating system: macOS
- Matplotlib version: 3.3.0rc1
- Matplotlib backend (
print(matplotlib.get_backend())
): MacOSX - Python version: 3.8.3
Installed using pip