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

     Tooltips in Lightning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Setup" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "from lightning import Lightning\n", "\n", "from numpy import random, asarray" ] }, { "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": [ "##
Turning on tooltips" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = random.rand(10)\n", "y = random.rand(10)\n", "\n", "lgn.scatter(x, y, size=10, tooltips=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's try adding explicit text labels. We'll make labels maked on random group assignments." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = random.rand(10)\n", "y = random.rand(10)\n", "g = (random.rand(10) * 5).astype('int')\n", "\n", "lgn.scatter(x, y, size=10, labels=['group ' + str(i) for i in g], tooltips=True, group=g)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
Labeling graph vertices" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "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.rand(25,25)\n", "mat[mat<0.8] = 0\n", "group = (random.rand(25) * 5).astype('int')\n", "labels = ['vertex ' + str(g) for g in group]\n", "\n", "lgn.force(mat, labels=labels, group=group)" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 0 }