0

I have a numpy array with a dtype of timedelta64[ns]. However, using this as the x-axis in a matplotlib plot comes out with labels 4.320, 4.325, 4.330, etc.

It seems as if matplotlib can't properly display timedelta64, how can I convert it to datetime.timedelta?

Sample time: 12:00:00.08012

printing arr[2] returns 0 days 12:00:00.08012

x = tbl.time
f, ax = plt.subplots(2, sharex=True)
ax[0].plot(x, tbl.column, label='test', color='red')
ax[1].plot(x, tbl.column2, label='test2', color='blue')
plt.show()
Supez38
  • 329
  • 1
  • 3
  • 16
  • How does 4.320 correspond to 12:00:00.08012 ? – ImportanceOfBeingErnest Nov 23 '18 at 19:26
  • No idea, the chart shows up with those labels and the list is 4746 elements long from 12:00:00 to 12:00:05. – Supez38 Nov 23 '18 at 19:37
  • Can you define the array in your question, to make all of this unambiguous, like `x = np.array(...)`, `y = ...`, `plt.plot(x,y)`? – ImportanceOfBeingErnest Nov 23 '18 at 19:45
  • I've added a sample, please check original post – Supez38 Nov 23 '18 at 20:00
  • Doesn't that just shift the question to what `tbl` is? What do I need to type into my editor to see the same result you are asking about here? – ImportanceOfBeingErnest Nov 23 '18 at 20:07
  • Tbl is a very large dataset. I've found a method online that converts a pandas series array with dt.to_pydatetime() that solves this but I now get an error 'TimeDeltaProperties' has no attribute of it. Probably need to upgrade pandas. You can assume the y axis to be arbitrary, the time column in tbl are in the format I've labeled as 'sample time' in my original post. – Supez38 Nov 23 '18 at 20:13
  • I suppose your question applies to just any sized dataset, so choose a small one, which you can type into the question. Maybe [this helps](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – ImportanceOfBeingErnest Nov 23 '18 at 20:15

0 Answers0