Home > database >  Pandas time plot without date
Pandas time plot without date

Time:01-04

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 (enter image description here

Not like this below.

enter image description here

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()

enter image description here

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:

enter image description here

  •  Tags:  
  • Related