Map plots in Lightning


Setup


In [1]:
from lightning import Lightning

from numpy import random

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


US Map

To make a US map with states colored by value, just pass a list of states, a list of values, and a colormap.


In [3]:
states = ["NA", "AK", "AL", "AR", "AZ", "CA", "CO","CT",
          "DC","DE","FL","GA","HI","IA","ID","IL","IN",
          "KS","KY","LA","MA","MD","ME","MI","MN","MO",
          "MS","MT","NC","ND","NE","NH","NJ","NM","NV",
          "NY","OH","OK","OR","PA","RI","SC","SD","TN",
          "TX","UT","VA","VI","VT","WA","WI","WV","WY"]

In [4]:
values = random.randn(len(states))
lgn.map(states, values, colormap='Purples')


Out[4]:

Discrete values are automatically handled for appriopriate colormaps


In [5]:
values = (random.rand(len(states)) * 5).astype('int')
lgn.map(states, values, colormap='Pastel1')


Out[5]:

Including our custom Lightning colormap


In [6]:
values = (random.rand(len(states)) * 5).astype('int')
lgn.map(states, values, colormap='Lightning')


Out[6]:


World Map

World maps are generated similarity, just use three-letter country codes instead of states


In [7]:
countries = ['ISO', 'SLE', 'COD', 'CAF', 'TCD', 'AGO', 'GNB', 'GNQ', 'MLI', 'MWI', 
             'BDI', 'NGA', 'SOM', 'SSD', 'MOZ', 'CIV', 'CMR', 'GIN', 'BFA', 'AFG', 
             'ZMB', 'MRT', 'SWZ', 'LSO', 'TGO', 'BEN', 'COG', 'COM', 'LBR', 'PAK', 
             'UGA', 'NER', 'DJI', 'YEM', 'TZA', 'GMB', 'RWA', 'ETH', 'KEN', 'TJK', 
             'GHA', 'SEN', 'ERI', 'MMR', 'ZWE', 'ZAF', 'GAB', 'KHM', 'TLS', 'IND', 
             'TKM', 'PNG', 'HTI', 'LAO', 'UZB', 'STP', 'BOL', 'MDG', 'NPL', 'ESH', 
             'BGD', 'NAM', 'SLB', 'AZE', 'BTN', 'KIR', 'BWA', 'KGZ', 'FSM', 'IRQ', 
             'MAR', 'PRY', 'GUY', 'MNG', 'GTM', 'DZA', 'DOM', 'IDN', 'VUT', 'HND', 
             'PRK', 'KAZ', 'TTO', 'JAM', 'BRA', 'EGY', 'PHL', 'WSM', 'PSE', 'SUR', 
             'TON', 'GEO', 'CPV', 'NIC', 'ECU', 'ARM', 'PER', 'IRN', 'SLV', 'JOR', 
             'COL', 'TUN', 'VCT', 'CHN', 'FJI', 'PAN', 'VEN', 'LBY', 'MEX', 'TUR', 
             'ALB', 'ABW', 'VNM', 'BLZ', 'MDA', 'MDV', 'NCL', 'SYR', 'GUF', 'SAU', 
             'ARG', 'MUS', 'URY', 'UKR', 'ROU', 'MKD', 'LCA', 'THA', 'BRB', 'GUM', 
             'MNE', 'VIR', 'LKA', 'GRD', 'SYC', 'BHS', 'ATG', 'LBN', 'CRI', 'BGR', 
             'OMN', 'KWT', 'BIH', 'PYF', 'BHR', 'LVA', 'MTQ', 'QAT', 'CHL', 'PRI', 
             'GLP', 'ARE', 'USA', 'BLR', 'SVK', 'POL', 'LTU', 'MLT', 'HRV', 'MYT', 
             'REU', 'HUN', 'CAN', 'TWN', 'BRN', 'CUB', 'MAC', 'NZL', 'GBR', 'MYS', 
             'EST', 'KOR', 'AUS', 'CYP', 'GRC', 'CHE', 'NLD', 'ISR', 'DNK', 'BEL', 
             'AUT', 'IRL', 'DEU', 'FRA', 'ESP', 'ITA', 'PRT', 'CZE', 'NOR', 'SVN', 
             'FIN', 'JPN', 'SWE', 'LUX', 'SGP', 'ISL', 'HKG', 'FLK', 'SMR', 'TCA', 
             'VAT', 'RUS', 'GRL']

Now plot random values. We'll also make it bigger so it's easier to see.


In [8]:
values = (random.rand(len(countries)) * 5).astype('int')
lgn.map(countries, values, colormap='Pastel1', width=900)


Out[8]: