1

I have this dataframe:

df.payout.head()

enter image description here

I am trying to plot stacked bar chart from pandas dataframe.

I want full date to be shown on X-axis label, though I only get only months if I use grouped.index.month or days for grouped.index.days:

import pandas as pd
import matplotlib.pyplot as plt

df.payout = pd.to_datetime(df.payout)

grouped = df.groupby(pd.Grouper(key='payout', freq='M')).sum()
grouped.plot(x=grouped.index.month, kind='bar', stacked=True)

plt.show()

How do I get payout values in YYYY-MM-DD format on X-axis?

enter image description here

1 Answer 1

2

Use the desired date format on the index:

grouped.plot(x=grouped.index.strftime('%Y-%m-%d'), kind='bar', stacked=True)
Sign up to request clarification or add additional context in comments.

2 Comments

thanks that worked. I'll choose your answer. offtopic: why I was downvoted?
Consider accepting it as an answer. I am not sure why you were down-voted, but If I had to guess, you didn't provide any sample data, just a screenshot which is not really helpful. Also, your question is about formatting date, the context of the stacked bar chart is redundant and may act as a diversion from the real problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.