Tooltips in Lightning


Setup

In [1]:
import os
from lightning import Lightning

from numpy import random, asarray

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


Turning on tooltips

Many plot types let you specify tooltips with the labels argument and the tooltips=True setting. First, turn on the setting for a simple scatter plot, and try clicking a point -- you should see it's x and y value appear above.

In [3]:
x = random.rand(10)
y = random.rand(10)

lgn.scatter(x, y, size=10, tooltips=True)
Out[3]:

Now let's try adding explicit text labels. We'll make labels maked on random group assignments.

In [4]:
x = random.rand(10)
y = random.rand(10)
g = (random.rand(10) * 5).astype('int')

lgn.scatter(x, y, size=10, labels=['group ' + str(i) for i in g], tooltips=True, group=g)
Out[4]:


Labeling graph vertices

A common use case for tooltips is in labeling graphs. Here we'll make a simple force network and label the vertices based on a group assignment.

In [5]:
mat = random.rand(25,25)
mat[mat<0.8] = 0
group = (random.rand(25) * 5).astype('int')
labels = ['vertex ' + str(g) for g in group]

lgn.force(mat, labels=labels, group=group)
Out[5]: