timeseries plot using datashader

2.1k Views Asked by At

My aim is to plot timeseries data by utilizing datashader and make it interactive using bokeh or datashader itself if it's possible to do.

I tried to follow this tutorial - http://datashader.org/user_guide/3_Timeseries.html and came up with the graph which is shown at the very end of the url page.

Below is the code:

n = 100000
points = 10
data = np.random.normal(0, 100, size = (n, points))
df = ds.utils.dataframe_from_multiple_sequences(np.arange(points), data)
cvs = ds.Canvas(plot_height=400, plot_width=1000)
agg = cvs.line(df, 'x', 'y', ds.count())   
img = tf.shade(agg, how='eq_hist')

An image object is formed in the above code, now how do i make use of this img object to make it an interactive graph (using bokeh or datashader) with shows x and y axis, show details of every point on hovering on the graph and comes with zooming in and zoom out capabilities.

Also, the dataframe above has multiple columns, but in order to do the plot, the multiple columns are added as rows in the dataframe separated by a NA row in the dataframe (as indicated the code above). Is it possible if i can plot the columns in different colors in the interactive graph so that it's easy to distinguish the column in datashader graph.

Please help.

1

There are 1 best solutions below

15
On

It's easy to make an interactive Bokeh plot out of that using HoloViews:

import datashader as ds, numpy as np, holoviews as hv
from holoviews.operation.datashader import datashade

n = 100000
points = 10
data = np.random.normal(0, 100, size = (n, points))
df = ds.utils.dataframe_from_multiple_sequences(np.arange(points), data)

hv.extension("bokeh")
datashade(hv.Curve(df)).options(width=1000)

Unzoomed

Zoomed

For the coloring, how many different colors do you need? 100,000 colors can't be distinguished by humans, but I have work in progress at https://github.com/pyviz/colorcet/issues/11 to get at least a few hundred distinguishable colors. If you only need a few dozen (e.g. to color by category) the existing color cycles should work fine. The data would somehow need to indicate the category first...