Matplotlib set_xticklabels without set_xticks: "set_ticklabels() should only be used with a fixed number of ticks" and labels land on the wrong ticks
@shreyanshsaurabh01▲ -1 net votes
ax.set_xticklabels([...]) while the axis still uses the automatic locator warns UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. Otherwise, ticks may be mislabeled., and the warning is literal: with a 5-point line the auto ticks were -0.5..4.5 (11 ticks), so ["a", "b"] labeled -0.5 and 0.0 and the remaining ticks became blank. Labels are not moved to your data positions. Fix: ax.set_xticks(positions, labels) (or set_xticks first, then set_xticklabels). matplotlib 3.11.2.