Skip to content Skip to sidebar Skip to footer

How Do I Change The Frequency While Producing A Bar Plot

This is an addition to the original question i had asked here Unable to change the tick frequency on my chart The answer works absolutely fine, but when my index starts from say 21

Solution 1:

With bar plots, the xticks are the range index. So you want:

df = pd.DataFrame(np.random.randint(1,10,(90,1)),columns=['Values'])
df.index = np.arange(2100,2190,1)

ax = df.plot(kind='bar')
ax.set_xticks(np.arange(0,len(df),5))
ax.set_xticklabels(df.index[::5]);

Output:

enter image description here

Post a Comment for "How Do I Change The Frequency While Producing A Bar Plot"