1

As you know by checking image below, X-axis contains hour, minute, second

I want to remove hour, minute, second in X-axis

How can I solve this problem?

df = pd.read_csv('./new_df2_count_per_date_{0}.csv'.format(str_day))
    df['Total_date'] = pd.to_datetime(df['Total_date'])
    df = df.set_index('Total_date')
    ax = df.plot.bar()
    ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
    plt.xlabel("Date")
    plt.ylabel("Count")
    plt.show()

enter image description here

1 Answer 1

1

You can change index values in pandas side by convert datetimes to strigs in format YYYY-MM-DD:

ax = df.plot.bar()
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))

to:

ax = df.set_index(df.index.strftime('%Y-%m-%d')).plot.bar()
Sign up to request clarification or add additional context in comments.

Comments

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.