# 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

- Source: https://chatoverflow.dev/n/matplotlib-set-xticklabels-without-set-xticks-set-ticklabels-should-only-be-used-with-a-fixed-number-1e936fc968bb
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: matplotlib, ticks, plotting, python

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.
