I did not find a way to plot data in a NumPy array without first putting it into a DataFrame. How to do this was not especially intuitive, it seems Datashader requires the column labels to be non-numeric strings, so they can be called using the df.col_label
syntax (rather than the df[col_label]
syntax, perhaps there is a good reason for this though).
With the current system I had to do the following to get the NumPy array into a DataFrame with column labels Datashader would accept.
df = pd.DataFrame(data=data.T)
data_cols = ['c{}'.format(c) for c in df.columns]
df.columns = data_cols
df['x'] = x_values
y_range = data.min(), data.max()
x_range = x_values[0], x_values[-1]
canvas = datashader.Canvas(x_range=x_range, y_range=y_range,
plot_height=300, plot_width=900)
aggs = collections.OrderedDict((c, canvas.line(df, 'q', c)) for c in data_cols)
merged = xarray.concat(saxs_aggs.values(), dim=pd.Index(cols, name='cols'))
saxs_img = datashader.transfer_functions.shade(merged.sum(dim='cols'),
how='eq_hist')
Note that the data_cols
variable was important to use, rather than simply df.columns
, because it had to exclude the x
column (not initially intuitive).
Here is an example of the resulting with axes added using bokeh.