0

I am going through a notebook available to plot time series using data shader and noticed that they have converted the time series vales to 'ms' and then used these values for x-axis

https://anaconda.org/jbednar/tseries/notebook

Can I have x-axis as datetime values while plotting time series data or does it have to converted to integer or float format ?

Thanks

RTM
  • 759
  • 2
  • 9
  • 22
  • 1
    Short answer: Better convert it to milliseconds. Dates are tricky as labels on an axis. – Dschoni Oct 11 '17 at 15:24
  • The reason that I am not willing to at this point is, I will loose some understanding of the data when I try to check for certain values at few particular times. This is very important for my visual analysis. I tried using bokeh for small dataset and it has no problem in displaying date time objects on x-axis unlike data shader – RTM Oct 11 '17 at 15:25
  • 1
    in your mentioned source, this actually happens further down ([in 12]) – Dschoni Oct 11 '17 at 15:28
  • The x-axis on the bokeh plot below [In 12] is still not in a date time format as it shows values like 32:20 ?? – RTM Oct 11 '17 at 15:30
  • 1
    That's because the data is given in relative times. Basically you can use the `DatetimeTickFormatter` as described here https://bokeh.pydata.org/en/latest/docs/reference/models/formatters.html – Dschoni Oct 11 '17 at 15:36
  • I didn't understand your comment about relative times. The author initialized the 'Time' column as integer values and then converted to date time format in 'ms'. Didn't he use the same column as is while making it interactive using bokeh ? – RTM Oct 11 '17 at 15:48

2 Answers2

1

Bokeh's low level, foundational representation of datetime values is "floating point milliseconds since epoch". So sending that is always an option. However, Bokeh can recognize and generally convert most common datetime data types automatically: numpy datetime arrays, Pandas datetime indices and series, python datetime objects, etc. so there is usually no need to convert to ms yourself.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • The x_range argument in Canvas method for datashader takes only real value as an input and can't give any timestamp directly. So I guess, the best approach for now is to convert the dates to milliseconds since epoch and give that values as tuple for x_range. This way, I don't have parse the entire data in milliseconds and should only convert two timestamps to milliseconds. Does that make sense ? – RTM Oct 11 '17 at 20:33
1

Datashader itself supports only real valued axes, but it is relatively simple to use HoloViews to construct a Bokeh plot of Datashader-rendered data labeled with date-time axes. You can see examples in Datashader's HoloViews_Datashader notebook:

enter image description here Basically, you can provide the real (actually int in this case) values to Datashader that it understands, but then convert them to human-readable dates before you label the axes.

James A. Bednar
  • 3,195
  • 1
  • 9
  • 13
  • Thanks a lot James. I have gone through some of the notebooks that you have on Datashader at anaconda but didn't notice this conversion explicitly. I converted the axis and currently trying to make it interactive using bokeh and using tools like HoverTool. I have an additional question. I created a simple bokeh plot with the same x_range and y_range that I have used for datashader plot. So can I overlay the datashader plot on this bokeh plot (non-empty) using base_plot() function that you have written ? – RTM Oct 11 '17 at 21:29
  • 1
    You can easily overlay HoloViews-based Bokeh plots, datshader or not; just do p1*p2. Normally you could extract a Bokeh figure from a HoloViews-based plot and combine it with Bokeh plots, and you could that for a Datashader plot, but then you would lose the dynamic zoom updating, so you probably don't want to do that. So I'd recommend trying to reformulate your Bokeh plot that you want to overlay as a HoloViews plot instead, which will make it all easy. – James A. Bednar Oct 12 '17 at 02:28