Line plots in Lightning


Setup

In [1]:
from lightning import Lightning

from numpy import random, asarray, arange
from sklearn import datasets
from scipy.ndimage.filters import gaussian_filter
from seaborn import color_palette

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


One random line with default styles

To experience Lightning's custom zoom behaviors, try zooming and panning with the alt or command keys held down.
Alt will only zoom/pan in x (especially useful for time series), and command for y.

In [3]:
y = gaussian_filter(random.rand(100), 3)
lgn.line(y)
Out[3]:


Setting line width and color

For a single line you can pass one size and color.

In [4]:
y = gaussian_filter(random.rand(100), 3)
lgn.line(y, thickness=10, color=[255,100,100])
Out[4]:


Multiple lines

Colors for multiple lines will automatically be assigned. Try hovering over a line to highlight it!

In [5]:
y = gaussian_filter(random.rand(5,100), [0, 3])
y = (y.T + arange(0,5)*0.2).T
lgn.line(y, thickness=6)
Out[5]:

You can also set colors and thicknesses yourself, providing one per line. Here we do so using a palette from seaborn.

In [6]:
y = gaussian_filter(random.rand(5,100), [0, 3])
y = (y.T + arange(0,5)*0.2).T
c = map(lambda x: list(asarray(x)*255), color_palette('Blues', 5))
s = [8, 10, 12, 14, 16]
lgn.line(y, thickness=s, color=c)
Out[6]:


Staggered lines and indices

It's possible to show multiple lines of unequal length.
Here we also demonstrate passing an index to set the xaxis (we assume the index corresponds to the longest of the lines).

In [7]:
y1 = gaussian_filter(random.rand(50), 5).tolist()
y2 = gaussian_filter(random.rand(75), 5).tolist()
y3 = gaussian_filter(random.rand(100), 5).tolist()
x = range(50,150)
lgn.line([y1,y2,y3], thickness=6, index=x)
Out[7]:


Clustered series with group labels

Instead of specifying colors directly as rgb, you can specify group assignments.
Here we use scikitlearn to generate clusters and then color according to cluster label.

In [8]:
d, g = datasets.make_blobs(n_features=5, n_samples=20, centers=5, cluster_std=1.0, random_state=100)
lgn.line(d, group=g)
Out[8]:


Axis labels

You can also label the axes.

In [9]:
y = gaussian_filter(random.rand(100), 3)
lgn.line(y, thickness=10, xaxis='variable #1', yaxis='variable #2')
Out[9]: