Matrix plots in Lightning


Setup

In [1]:
from lightning import Lightning

from numpy import random, arange, asarray, corrcoef, argsort, array
import networkx as nx
from sklearn import datasets

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


Simple matrix

Matrices are useful ways to visualize dense tables and correlation matrices data.
First we show a random matrix with default styles.
You can us the arrow keys to change the contrast (up/down) or the colormap (left/right).

In [3]:
mat = random.randn(10,10)
lgn.matrix(mat)
Out[3]:


Different shapes

Rectanglular matrices will automatically size appropriately.

In [4]:
mat = random.randn(10,20)
lgn.matrix(mat)
Out[4]:
In [5]:
mat = random.randn(20,10)
lgn.matrix(mat)
Out[5]:


Colors

Matrices can be rendered using any colorbrewer colormaps.

In [6]:
mat = random.rand(10,10)
lgn.matrix(mat, colormap='Reds')
Out[6]:
In [7]:
mat = random.rand(10,10)
lgn.matrix(mat, colormap='Spectral')
Out[7]:


Labels

You can label the rows and columns of a matrix. Clicking on the text labels will highlight those rows and columns -- try it!

In [8]:
n, m = (8, 16)
mat = arange(n*m).reshape(n,m)
rows = ['row ' + str(i) for i in range(n)]
columns = ['col ' + str(i) for i in range(m)]

lgn.matrix(mat, row_labels=rows, column_labels=columns)
Out[8]:

You can also turn on labeling of cells by their value.

In [9]:
mat = arange(n*m).reshape(n,m)

lgn.matrix(mat, numbers=True)
Out[9]: