I've been trying hard all day long, but couldn't figure this one out. Maybe simple, but I can't get this one. There is a similar question (
Not like this below.
Any help would be greatly appreciated. Thank you in advance!
CodePudding user response:
Coerce date_time to datetime and extract the time component using strftime and the plot
df['time']=pd.to_datetime(df['date_time']).dt.strftime('%H:%M:%S')
plt.plot(df['time'], df['value'],'o--', lw=0);
plt.show()
If you wanted rounded up time, see code below.
df['time']=pd.to_datetime(df['date_time']).round('T').dt.strftime('%H:%M:%S')
plt.plot(df['time'], df['value'],'o--', lw=0);
plt.show()
CodePudding user response:
This answer is if you're looking to simply change the tick labels. Basically, using set_xticklabels
change the xticklabels from the default to hourly:
f, ax = plt.subplots(1,1)
ax.plot(df['date_time'], df['value'],'o--', lw=0)
ax.set_xticks(df['date_time'])
ax.set_xticklabels(df['date_time'].str.split(',').str[1]);
Output: