from lightning import Lightning

from numpy import random, asarray, arange
from sklearn import datasets
from scipy.ndimage.filters import gaussian_filter
from seaborn import color_palette

"""
Explanation: <img style='float: left' src="http://lightning-viz.github.io/images/logo.png"> <br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Line plots in <a href='http://lightning-viz.github.io/'><font color='#9175f0'>Lightning</font></a>
<hr> Setup
End of explanation
"""


lgn = Lightning(ipython=True, host='http://public.lightning-viz.org')

"""
Explanation: Connect to server
End of explanation
"""


y = gaussian_filter(random.rand(100), 3)
lgn.line(y)

"""
Explanation: <hr> One random line with default styles
To experience Lightning's custom zoom behaviors, try zooming and panning with the alt or command keys held down.
<br>
Alt will only zoom/pan in x (especially useful for time series), and command for y.
End of explanation
"""


y = gaussian_filter(random.rand(100), 3)
lgn.line(y, thickness=10, color=[255,100,100])

"""
Explanation: <hr> Setting line width and color
For a single line you can pass one size and color.
End of explanation
"""


y = gaussian_filter(random.rand(5,100), [0, 3])
y = (y.T + arange(0,5)*0.2).T
lgn.line(y, thickness=6)

"""
Explanation: <hr> Multiple lines
Colors for multiple lines will automatically be assigned. Try hovering over a line to highlight it!
End of explanation
"""


y = gaussian_filter(random.rand(5,100), [0, 3])
y = (y.T + arange(0,5)*0.2).T
c = map(lambda x: list(asarray(x)*255), color_palette('Blues', 5))
s = [8, 10, 12, 14, 16]
lgn.line(y, thickness=s, color=c)

"""
Explanation: You can also set colors and thicknesses yourself, providing one per line. Here we do so using a palette from seaborn.
End of explanation
"""


y1 = gaussian_filter(random.rand(50), 5).tolist()
y2 = gaussian_filter(random.rand(75), 5).tolist()
y3 = gaussian_filter(random.rand(100), 5).tolist()
x = range(50,150)
lgn.line([y1,y2,y3], thickness=6, index=x)

"""
Explanation: <hr> Staggered lines and indices
It's possible to show multiple lines of unequal length. 
<br>
Here we also demonstrate passing an index to set the xaxis (we assume the index corresponds to the longest of the lines).
End of explanation
"""


d, g = datasets.make_blobs(n_features=5, n_samples=20, centers=5, cluster_std=1.0, random_state=100)
lgn.line(d, group=g)

"""
Explanation: <hr> Clustered series with group labels
Instead of specifying colors directly as rgb, you can specify group assignments.
<br>
Here we use scikitlearn to generate clusters and then color according to cluster label.
End of explanation
"""


y = gaussian_filter(random.rand(100), 3)
lgn.line(y, thickness=10, xaxis='variable #1', yaxis='variable #2')

"""
Explanation: <hr> Axis labels
You can also label the axes.
End of explanation
"""


