"
],
"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": [
"## Random binary network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A random graph where every node has the same degree, with default styling.\n",
" \n",
"This and other graph plots take matrices (e.g. adjacency matrices) as inputs.\n",
" \n",
"We use the `networkx` library to generate the graph, then get its adjancency matrix.\n",
" \n",
"Double click on a point to see its neighbors (all should have 3).\n",
" \n",
"Drag points to try and move the graph, it should remain tight because of the degree structure."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n = 100\n",
"G = nx.random_regular_graph(3,n)\n",
"mat = nx.adjacency_matrix(G).todense()\n",
"lgn.force(mat)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random weighted network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The previous network was binary (all links either 0 or 1).\n",
"Here the links are weighted, which is reflected in the line widths."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G = nx.random_regular_graph(3,100)\n",
"mat = asarray(nx.adjacency_matrix(G).todense()) * (((random.rand(100,100))*5) ** 2)\n",
"lgn.force(mat)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lobster network"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The lobster graph, a backbone with some leaves, is colored here by node ordering.\n",
" \n",
"We also set all nodes with degree less than 2 to gray."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G = nx.random_lobster(60, 0.5, 0.0, seed=44)\n",
"mat = nx.adjacency_matrix(G).todense()\n",
"n = len(G.nodes())\n",
"c = [list(asarray(hsv_to_rgb(float(x) / n , 0.8, 1.0))*255) if y > 1 else [150,150,150] for (x,y) in G.degree_iter()]\n",
"lgn.force(mat, color=c)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Coloring by degree"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we color points (and also change their size) to indicate their degree.\n",
" \n",
"Click to confirm bigger points have more connections."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G = nx.random_geometric_graph(50, 0.1)\n",
"mat = nx.adjacency_matrix(G).todense()\n",
"g = G.degree().values()\n",
"lgn.force(mat, group=g, size=(asarray(g) + 1.5)*3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Graph of clustering"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Graphs can be a useful way to look at data that doesn't neccessarily come from a graph.\n",
" \n",
"Here we create a graph from a thresholded correlation matrix on data drawn from a set of clusters.\n",
" \n",
"The cluster identities are clear in the resulting graph."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"