0

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 2100 (instead of 0) in my original Q,the graph looks incorrect.

How do I fix it?

import numpy as np
import pandas as pd

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

enter image description here

user13412850
  • 509
  • 1
  • 5
  • 16

1 Answers1

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

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74