Reputation: 11
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()
Upvotes: 1
Views: 64
Reputation: 862641
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()
Upvotes: 1