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

     Map 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" ] }, { "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": [ "##
US Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make a US map with states colored by value, just pass a list of states, a list of values, and a colormap." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "states = [\"NA\", \"AK\", \"AL\", \"AR\", \"AZ\", \"CA\", \"CO\",\"CT\",\n", " \"DC\",\"DE\",\"FL\",\"GA\",\"HI\",\"IA\",\"ID\",\"IL\",\"IN\",\n", " \"KS\",\"KY\",\"LA\",\"MA\",\"MD\",\"ME\",\"MI\",\"MN\",\"MO\",\n", " \"MS\",\"MT\",\"NC\",\"ND\",\"NE\",\"NH\",\"NJ\",\"NM\",\"NV\",\n", " \"NY\",\"OH\",\"OK\",\"OR\",\"PA\",\"RI\",\"SC\",\"SD\",\"TN\",\n", " \"TX\",\"UT\",\"VA\",\"VI\",\"VT\",\"WA\",\"WI\",\"WV\",\"WY\"]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = random.randn(len(states))\n", "lgn.map(states, values, colormap='Purples')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Discrete values are automatically handled for appriopriate colormaps" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = (random.rand(len(states)) * 5).astype('int')\n", "lgn.map(states, values, colormap='Pastel1')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Including our custom Lightning colormap" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = (random.rand(len(states)) * 5).astype('int')\n", "lgn.map(states, values, colormap='Lightning')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##
World Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "World maps are generated similarity, just use three-letter country codes instead of states" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "countries = ['ISO', 'SLE', 'COD', 'CAF', 'TCD', 'AGO', 'GNB', 'GNQ', 'MLI', 'MWI', \n", " 'BDI', 'NGA', 'SOM', 'SSD', 'MOZ', 'CIV', 'CMR', 'GIN', 'BFA', 'AFG', \n", " 'ZMB', 'MRT', 'SWZ', 'LSO', 'TGO', 'BEN', 'COG', 'COM', 'LBR', 'PAK', \n", " 'UGA', 'NER', 'DJI', 'YEM', 'TZA', 'GMB', 'RWA', 'ETH', 'KEN', 'TJK', \n", " 'GHA', 'SEN', 'ERI', 'MMR', 'ZWE', 'ZAF', 'GAB', 'KHM', 'TLS', 'IND', \n", " 'TKM', 'PNG', 'HTI', 'LAO', 'UZB', 'STP', 'BOL', 'MDG', 'NPL', 'ESH', \n", " 'BGD', 'NAM', 'SLB', 'AZE', 'BTN', 'KIR', 'BWA', 'KGZ', 'FSM', 'IRQ', \n", " 'MAR', 'PRY', 'GUY', 'MNG', 'GTM', 'DZA', 'DOM', 'IDN', 'VUT', 'HND', \n", " 'PRK', 'KAZ', 'TTO', 'JAM', 'BRA', 'EGY', 'PHL', 'WSM', 'PSE', 'SUR', \n", " 'TON', 'GEO', 'CPV', 'NIC', 'ECU', 'ARM', 'PER', 'IRN', 'SLV', 'JOR', \n", " 'COL', 'TUN', 'VCT', 'CHN', 'FJI', 'PAN', 'VEN', 'LBY', 'MEX', 'TUR', \n", " 'ALB', 'ABW', 'VNM', 'BLZ', 'MDA', 'MDV', 'NCL', 'SYR', 'GUF', 'SAU', \n", " 'ARG', 'MUS', 'URY', 'UKR', 'ROU', 'MKD', 'LCA', 'THA', 'BRB', 'GUM', \n", " 'MNE', 'VIR', 'LKA', 'GRD', 'SYC', 'BHS', 'ATG', 'LBN', 'CRI', 'BGR', \n", " 'OMN', 'KWT', 'BIH', 'PYF', 'BHR', 'LVA', 'MTQ', 'QAT', 'CHL', 'PRI', \n", " 'GLP', 'ARE', 'USA', 'BLR', 'SVK', 'POL', 'LTU', 'MLT', 'HRV', 'MYT', \n", " 'REU', 'HUN', 'CAN', 'TWN', 'BRN', 'CUB', 'MAC', 'NZL', 'GBR', 'MYS', \n", " 'EST', 'KOR', 'AUS', 'CYP', 'GRC', 'CHE', 'NLD', 'ISR', 'DNK', 'BEL', \n", " 'AUT', 'IRL', 'DEU', 'FRA', 'ESP', 'ITA', 'PRT', 'CZE', 'NOR', 'SVN', \n", " 'FIN', 'JPN', 'SWE', 'LUX', 'SGP', 'ISL', 'HKG', 'FLK', 'SMR', 'TCA', \n", " 'VAT', 'RUS', 'GRL']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now plot random values. We'll also make it bigger so it's easier to see." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "values = (random.rand(len(countries)) * 5).astype('int')\n", "lgn.map(countries, values, colormap='Pastel1', width=900)" ] } ], "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 }