0

While trying to plot timedate gaps using the Matplotlib broken_barh API I get an error:

--> 538     return array(a, dtype, copy=False, order=order)
    539 
    540 

ValueError: Could not convert object to NumPy datetime

I am using Jupiter notebook in Windows 10 Pro 64bits with Python 3.6.1

My pandas DataFrame is:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 266 entries, 0 to 265
Data columns (total 9 columns):
End Seq         266 non-null int64
End Time        266 non-null datetime64[ns]
Gap Seq         266 non-null int64
Gap Time        266 non-null float64
Source          266 non-null object
Start Seq       266 non-null int64
Start Time      266 non-null datetime64[ns]
Target          266 non-null object
Gap Time (s)    266 non-null timedelta64[ns]
dtypes: datetime64[ns](2), float64(1), int64(3), object(2), 
timedelta64[ns](1)
memory usage: 18.8+ KB

I have googled a lot and have not been able to find any reasonable explanation as to why this is not working.

This is the code I am using in my jupyter notebook:

fig, ax = plt.subplots()

ax.broken_barh(list(zip(df['Start Time'].values, (df['Gap Time 
(s)']).values)), (0, 0.5))

ax.set_ylim(-2,2)
plt.show()

My expectation as to have jupyter display a barh graph like:

https://matplotlib.org/devdocs/gallery/lines_bars_and_markers/broken_barh.html

Francisco
  • 389
  • 1
  • 4
  • 14
  • looks like `timedelta64[ns]` does not work with `np.timedelta` or `broken_barh` expects to time series, not `timedelta` series. – Quang Hoang May 01 '19 at 14:55
  • @QuangHoang That is correct, the conversion process within mathplotlib seems to be not completely correct, my ignorance on the subject and inner workings keeps me from understanding completely how to proceed from here on – Francisco May 02 '19 at 14:34
  • Check [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples); I think if you had included such [mcve] in your question from the start, you would have gotten an answer to this already by now. – ImportanceOfBeingErnest May 03 '19 at 10:25
  • @ImportanceOfBeingErnest Due to NDA and other legalities, I can not include much more. – Francisco May 06 '19 at 14:03
  • Noone is interested in any real-word data anyways. A [mcve] contains data that you produce programatically inside the code to reproduce the issue. – ImportanceOfBeingErnest May 06 '19 at 14:16

0 Answers0