{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#

     Matrix plots in Lightning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from lightning import Lightning\n", "\n", "from numpy import random, arange, asarray, corrcoef, argsort, array\n", "import networkx as nx\n", "from sklearn import datasets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect to server" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
Lightning initialized
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Connected to server at http://public.lightning-viz.org\n" ] }, { "data": { "application/javascript": [ "(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error(\"Cannot find module '\"+o+\"'\")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lgn = Lightning(ipython=True, host='http://public.lightning-viz.org')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Simple matrix" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Matrices are useful ways to visualize dense tables and correlation matrices data.\n", "
\n", "First we show a random matrix with default styles.\n", "
\n", "You can us the arrow keys to change the contrast (up/down) or the colormap (left/right)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = random.randn(10,10)\n", "lgn.matrix(mat)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Different shapes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Rectanglular matrices will automatically size appropriately." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = random.randn(10,20)\n", "lgn.matrix(mat)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = random.randn(20,10)\n", "lgn.matrix(mat)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Colors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Matrices can be rendered using any colorbrewer colormaps." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = random.rand(10,10)\n", "lgn.matrix(mat, colormap='Reds')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = random.rand(10,10)\n", "lgn.matrix(mat, colormap='Spectral')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Labels" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can label the rows and columns of a matrix. Clicking on the text labels will highlight those rows and columns -- try it!" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n, m = (8, 16)\n", "mat = arange(n*m).reshape(n,m)\n", "rows = ['row ' + str(i) for i in range(n)]\n", "columns = ['col ' + str(i) for i in range(m)]\n", "\n", "lgn.matrix(mat, row_labels=rows, column_labels=columns)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also turn on labeling of cells by their value." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mat = arange(n*m).reshape(n,m)\n", "\n", "lgn.matrix(mat, numbers=True)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.9" } }, "nbformat": 4, "nbformat_minor": 0 }