How To Do Linked Data Selections In Holoviews With Datashader + Bokeh Backend
Let me just start by complementing the HoloViews developers, this thing is pretty amazing. There are just a lot of pieces and it is a bit hard to figure out how to put them all tog
Solution 1:
You can use HoloViews Streams to select the data to display using only the currently visible points. There's an example at: https://anaconda.org/petrenko/linking_datashaders
Solution 2:
Working from James' answer (https://stackoverflow.com/a/44288019/1447953) I extended the example in the question to the following. It takes one plot as the "master" control source, and plots only data that appears within the data ranges of that plot onto a bunch of "slave" plots. It would be nice to have a dual-way relationship, but this is pretty cool as it is.
import numpy as np
import pandas as pd
import holoviews as hv
import holoviews.operation.datashader as hvds
hv.notebook_extension('bokeh')
%opts Layout [shared_axes=False shared_datasource=True]
# Create some data to plot
x1 = np.arange(0,10,1e-2)
x2 = np.arange(0,10,1e-2)
X1,X2 = np.meshgrid(x1,x2)
x1 = X1.flatten()
x2 = X2.flatten()
x3 = np.sin(x1) * np.cos(x2)
x4 = x1**2 + x2**2# Pandas dataframe object from the data print"Creating Pandas dataframe object"
df = pd.DataFrame.from_dict({"x1": x1, "x2": x2, "x3": x3, "x4": x4})
# Make some linked scatter plots using datashader
x1_x2 = hv.Points(df[['x1', 'x2']])
#x1_x3 = hv.Points(df[['x1', 'x3']])#x2_x4 = hv.Points(df[['x2', 'x4']])from holoviews import streams
maindata=x1_x2
mainx='x1'
mainy='x2'defcreate_dynamic_map(xvar,yvar):
deflink_function(x_range, y_range):
x_min = x_range[0]; x_max = x_range[1]
y_min = y_range[0]; y_max = y_range[1]
pts = hv.Points(df[ (getattr(df,mainx) > x_min) & (getattr(df,mainx) < x_max)
& (getattr(df,mainy) > y_min) & (getattr(df,mainy) < y_max)
][[xvar, yvar]])
return pts
dmap = hv.DynamicMap(link_function,
streams=[hv.streams.RangeXY(x_range=(-100,100),
y_range=(-100,100),
source=maindata)],
kdims=[])
return dmap
x1_x3 = create_dynamic_map('x1','x3')
x2_x4 = create_dynamic_map('x2','x4')
hvds.datashade(x1_x2) + hvds.datashade(x1_x3) + hvds.datashade(x2_x4)
Post a Comment for "How To Do Linked Data Selections In Holoviews With Datashader + Bokeh Backend"