Created
February 23, 2021 08:44
-
-
Save epifanio/951e518924bf56daa64fcd82459243cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import holoviews as hv | |
from holoviews import opts | |
from holoviews.operation import decimate | |
from holoviews.operation.datashader import datashade, dynspread | |
hv.extension("bokeh") | |
decimate.max_samples = 5000 | |
dynspread.max_px = 20 | |
dynspread.threshold = 0.5 | |
opts.defaults(opts.Points(tools=["box_select", "lasso_select"])) | |
# Declare some points | |
points = hv.Points(np.random.randn(1000, 2)) | |
# Declare points as source of selection stream | |
selection = streams.Selection1D(source=points) | |
# Write function that uses the selection indices to slice points and compute stats | |
def selected_info(index): | |
selected = points.iloc[index] | |
if index: | |
label = "Mean x, y: %.3f, %.3f" % tuple(selected.array().mean(axis=0)) | |
else: | |
label = "No selection" | |
return selected.relabel(label).opts(color="red") | |
# Combine points and DynamicMap | |
points + hv.DynamicMap(selected_info, streams=[selection]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment