In [1]:
from lightning import Lightning
from numpy import random
Lightning was designed as a API-based visualization server, to which data is posted, and from which visualizations are returned. However, there are many use cases where operating without a server is desirable. For example, when doing data analysis locally, or when we're using notebooks like Jupyter.
For this use case, Lightning offers a "local" mode that doesn't require a server, or even internet access. This is a particularly easy way to get started with Lightning because it only requires a client installation! Once you've installed the Python client with pip
, all you need to do is set local mode to true.
In [2]:
lgn = Lightning(ipython=True, local=True)
Then generate a plot. It'll automatically embed in the notebook (because we set ipython=True
). Local plots are interactive just like plots rendered using the server! Try zooming and panning.
In [3]:
series = random.randn(5, 50)
lgn.line(series)
Out[3]:
Performance can often be a little better for local plots with large data sets, because there is no data transfer.
In [4]:
x = random.randn(1000)
y = random.randn(1000)
v = random.randn(1000)
lgn.scatter(x, y, alpha=0.5, values=v, colormap='Reds')
Out[4]:
And most plot types are available. Here's a force visualization.
In [5]:
mat = random.rand(100,100)
mat[mat<0.97] = 0
lgn.force(mat)
Out[5]:
And here's a map!
In [6]:
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"]
values = random.randn(len(states))
lgn.map(states, values, colormap='Greens')
Out[6]:
You can also save a visualization to html, which is useful if you are using local mode without a notebook. First create the visualization.
In [7]:
viz = lgn.scatter(random.randn(10), random.randn(10))
Then save using viz.save_html('filename')
Some visualizations are not available in local mode, for example, plots that use images (though we are working on expanding coverage).
In [8]:
lgn.image(random.randn(25,25))
And although full interactivity is supported, there is currently no way to extract user selections from a visualization. For that, take a look at the various ways of running Lightning with a server!