how to plot columns by column group in time series data

Viewed 31
df= speed  status  timestamp      
     20     TRUE   9/10/2022..    
     30     TRUE   9/10/2022..    
     10     FALSE  9/08/2022..   
     ... 

I want to plot the speeds by status through time, however the start-end times are not the same for TRUE and FALSE. I want them the start at the same point on the plot.

x-axis = time

y-axis = speed

TRUE and FALSE are denoted with different color lines on the plot. so comparing speeds of TRUE and FALSE

1 Answers

Seaborn or Plotly packages do this out-of-the box better than matplotlib. you used matplotlib tag but didn't mention it in your question, so here's an answer using Seaborn:

import seaborn as sns

df = your_data_loading

sns.lineplot(data=df, x='time', y='speed', hue='status')
Related