1
$\begingroup$

I am trying to visualize Time series data is as follows enter image description here

following is my code to plot the data

plt.plot(data['date'], data['c_16_avg_a'])

plt.xticks(rotation='vertical')

the date is getting truncated here. and the plot looks wired.

Any suggestions will greatly be appreciated

enter image description here

$\endgroup$
1
  • $\begingroup$Are your values sorted by the date (increasing)? If not matplotlib will simply go in the order the values are provided (i.e. go forwards and backwards) in time.$\endgroup$
    – Oxbowerce
    CommentedJan 27, 2021 at 8:36

1 Answer 1

1
$\begingroup$

This is happening because the dates in your column are not sorted. To fix this either sort the values by the date column or, even better, plot using the timestamps instead of their dates. Matplotlib inherently handles datetime format better than it does datest represented as strings!

The best option however, is to add the timestamps as the dataframe's index and use pd.Series.plot() instead of matplotlib.

data.index = data['time_stamp'] data['c_16_avg_a'].plot() 
$\endgroup$

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.