# Brushing in Lightning

## Setup

In [1]:
from lightning import Lightning

from numpy import random, zeros


## Connect to server¶

In [2]:
lgn = Lightning(ipython=True, host='http://public.lightning-viz.org')

Lightning initialized
Connected to server at 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.

In [3]:
x = random.randn(100)
y = random.randn(100)

lgn.scatter(x, y, brush=True, zoom=False)

Out[3]:

## Getting selections

If working with a Lightning server (rather than the server-less mode), we can easily extract the points we've selected.

In [4]:
x = random.rand(100) * 10
y = random.rand(100) * 10

viz = lgn.scatter(x, y, brush=True, zoom=False)
viz

Out[4]:

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.

In [5]:
sx, sy = viz.points()

In [6]:
lgn.scatter(sx, sy, zoom=False)

Out[6]:

I can use a different accessor, selected, to grab the indices of the selected points.

In [7]:
inds = viz.selected()


Let's replot all points, but show the selected ones in a different color.

In [8]:
groups = zeros(100)
groups[inds] = 1

lgn.scatter(x, y, group=groups, zoom=False)

Out[8]: