'Pandas plot align x tick labels when using major_locator

How do I center the x tick labels in a line plot?

ax.set_xticklabels(ax.get_xticklabels(), ha='center')
>> <ipython-input-161-99c31b694cb8>:7:
   UserWarning: FixedFormatter should only be used together with FixedLocator
   ax.set_xticklabels(ax.get_xticklabels(), ha='center')

Pandas version: 1.4.1

Matplotlib version: 3.5.1

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source