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.
lgn = Lightning(ipython=True, local=True)
Running local mode, some functionality limited.
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.
series = random.randn(5, 50)
lgn.line(series)
Performance can often be a little better for local plots with large data sets, because there is no data transfer.
x = random.randn(1000)
y = random.randn(1000)
v = random.randn(1000)
lgn.scatter(x, y, alpha=0.5, values=v, colormap='Reds')
And most plot types are available. Here's a force visualization.
mat = random.rand(100,100)
mat[mat<0.97] = 0
lgn.force(mat)
And here's a map!
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')
You can also save a visualization to html, which is useful if you are using local mode without a notebook. First create the visualization.
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).
lgn.image(random.randn(25,25))
Plots of type 'image' not yet supported in local mode
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!