I'm getting some overcrowding for the tick labels on the x-axis of a matplotlib chart, so I'm thinking to reduce the frequency at which the labels appear. There seems to be a few functions for this (multiplelocator, maxnlocator) but these just space the existing labels out, rather than skipping any actual labels. For example, if I run this
df = pd.DataFrame(columns=['bond 1','bond 2'],
index=[2017,2018,2019,2020,2021,2022])
df['bond 1'] = [4,5,6,6,5,4]
df['bond 2'] = [8,6,4,4,6,8]
fig,ax=plt.subplots(1)
ax = df.plot(ax=ax, kind='bar', colormap='copper')
locator = tick.MultipleLocator(base=2)
ax.xaxis.set_major_locator(locator)
In terms of format this looks great, but the data points are actually mis-labelled - where it says 2018 is actually the 2017 data, where it says 2020 is the 2021 data.
Could anyone let me know if there's any easy way to space the labels out without having them map onto the wrong data points?
Thanks!