Reputation: 1
df = pd.DataFrame({"hour": range(4,24,1),
"rate": np.random.random(size = len(range(4,24,1)))
}, columns = ["hour", "rate"]).set_index("hour")
fig, ax = plt.subplots(1,1, figsize = (12, 8))
df.plot(kind = "bar", xlim = (0,24), ax = ax);
Need to have a bar for each hour, but xticks labels only aligns with the index.
Upvotes: 0
Views: 530
Reputation: 36691
Why not just add the other values to the index?
df = pd.concat([pd.DataFrame([0]*4, columns=['rate']), df])
df.index.name = 'hour'
fig, ax = plt.subplots(1,1, figsize = (12, 8))
df.plot(kind = "bar", xlim = (0,24), ax=ax)
Upvotes: 1