from lightning import Lightning
from numpy import random, zeros
lgn = Lightning(ipython=True, host='http://public.lightning-viz.org')
Several visualizations support brushing, including graphs, force networks, and scatter plots. Just set brush=True
, then SHIFT-click and drag to select points. You should see them highlighted as you drag. We'll also turn off zooming for these examples, which can simplify our interactions with the plot.
x = random.randn(100)
y = random.randn(100)
lgn.scatter(x, y, brush=True, zoom=False)
If working with a Lightning server (rather than the server-less mode), we can easily extract the points we've selected.
x = random.rand(100) * 10
y = random.rand(100) * 10
viz = lgn.scatter(x, y, brush=True, zoom=False)
viz
Let's say I use the brush in the visualization above to select all points between 0 and 4. Below, I grab those points, and replot them -- note the new scale.
sx, sy = viz.points()
lgn.scatter(sx, sy, zoom=False)
I can use a different accessor, selected
, to grab the indices of the selected points.
inds = viz.selected()
Let's replot all points, but show the selected ones in a different color.
groups = zeros(100)
groups[inds] = 1
lgn.scatter(x, y, group=groups, zoom=False)