Skip to content

Commit 9adfd5c

Browse files
committed
Add support for value color specification
1 parent a231b9e commit 9adfd5c

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

lightning/types/plots.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Scatter(Base):
1919
_name = 'scatter'
2020

2121
@staticmethod
22-
def clean(x, y, color=None, label=None, size=None, alpha=None, xaxis=None, yaxis=None):
22+
def clean(x, y, color=None, label=None, value=None, colormap=None, size=None, alpha=None, xaxis=None, yaxis=None):
2323
"""
2424
Plot two-dimensional data as points.
2525
@@ -36,6 +36,12 @@ def clean(x, y, color=None, label=None, size=None, alpha=None, xaxis=None, yaxis
3636
label : array-like, optional, singleton or (n,)
3737
Single integer or array to set colors via groups
3838
39+
value : array-like, optional, singleton or (n,)
40+
Values to set node colors via a linear scale
41+
42+
colormap : string
43+
Specification of color map, only colorbrewer types supported
44+
3945
size : array-like, optional, singleton or (n,)
4046
Single size or array to set point sizes
4147
@@ -54,6 +60,8 @@ def clean(x, y, color=None, label=None, size=None, alpha=None, xaxis=None, yaxis
5460

5561
outdict = add_property(outdict, color, 'color')
5662
outdict = add_property(outdict, label, 'label')
63+
outdict = add_property(outdict, value, 'value')
64+
outdict = add_property(outdict, colormap, 'colormap')
5765
outdict = add_property(outdict, size, 'size')
5866
outdict = add_property(outdict, alpha, 'alpha')
5967
outdict = add_property(outdict, xaxis, 'xaxis')
@@ -113,8 +121,8 @@ def clean(conn, label=None):
113121
either 2 elements per link (source, target),
114122
or 3 elements (source, target, value).
115123
116-
colormap : string
117-
Specification of color map, only colorbrewer types supported
124+
label : array-like, optional, singleton or (n,)
125+
Single integer or array to set colors via groups
118126
"""
119127
links = parse_links(conn)
120128
nodes = parse_nodes(conn)
@@ -166,9 +174,6 @@ def clean(series, index=None, color=None, label=None, size=None, xaxis=None, yax
166174
size : array-like, optional, singleton or (n,)
167175
Single size or array to set line thickness
168176
169-
size : array-like, optional, singleton or (n,)
170-
Single size or array to set line thickness
171-
172177
xaxis : str, optional, default = None
173178
Label for x-axis
174179
@@ -235,7 +240,7 @@ class Force(Base):
235240
_func = 'force'
236241

237242
@staticmethod
238-
def clean(conn, color=None, label=None, size=None):
243+
def clean(conn, color=None, label=None, value=None, colormap=None, size=None):
239244
"""
240245
Create a force-directed network from a connectivity matrix.
241246
@@ -255,6 +260,12 @@ def clean(conn, color=None, label=None, size=None):
255260
label : array-like, optional, singleton or (n,)
256261
Single integer or array to set node colors via group labels
257262
263+
value : array-like, optional, singleton or (n,)
264+
Values to set node colors via a linear scale
265+
266+
colormap : string
267+
Specification of color map, only colorbrewer types supported
268+
258269
size : array-like, optional, singleton or (n,)
259270
Single size or array to set node sizes
260271
"""
@@ -266,6 +277,8 @@ def clean(conn, color=None, label=None, size=None):
266277

267278
outdict = add_property(outdict, color, 'color')
268279
outdict = add_property(outdict, label, 'label')
280+
outdict = add_property(outdict, value, 'value')
281+
outdict = add_property(outdict, colormap, 'colormap')
269282
outdict = add_property(outdict, size, 'size')
270283

271284
return outdict
@@ -277,7 +290,7 @@ class Graph(Base):
277290
_func = 'graph'
278291

279292
@staticmethod
280-
def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
293+
def clean(x, y, conn, color=None, label=None, value=None, colormap=None, size=None, imagedata=None):
281294
"""
282295
Create a node-link graph from spatial points and their connectivity matrix.
283296
@@ -300,6 +313,12 @@ def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
300313
label : array-like, optional, singleton or (n,)
301314
Single integer or array to set node colors via group labels
302315
316+
value : array-like, optional, singleton or (n,)
317+
Values to set node colors via a linear scale
318+
319+
colormap : string
320+
Specification of color map, only colorbrewer types supported
321+
303322
size : array-like, optional, singleton or (n,)
304323
Single size or array to set node sizes
305324
"""
@@ -311,6 +330,8 @@ def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
311330

312331
outdict = add_property(outdict, color, 'color')
313332
outdict = add_property(outdict, label, 'label')
333+
outdict = add_property(outdict, value, 'value')
334+
outdict = add_property(outdict, colormap, 'colormap')
314335
outdict = add_property(outdict, size, 'size')
315336

316337
if imagedata is not None:
@@ -327,7 +348,7 @@ class GraphBundled(Base):
327348
_func = 'graphbundled'
328349

329350
@staticmethod
330-
def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
351+
def clean(x, y, conn, color=None, label=None, value=None, colormap=None, size=None, imagedata=None):
331352
"""
332353
Create a node-link graph with bundled edges.
333354
@@ -350,6 +371,12 @@ def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
350371
label : array-like, optional, singleton or (n,)
351372
Single integer or array to set node colors via group labels
352373
374+
value : array-like, optional, singleton or (n,)
375+
Values to set node colors via a linear scale
376+
377+
colormap : string
378+
Specification of color map, only colorbrewer types supported
379+
353380
size : array-like, optional, singleton or (n,)
354381
Single size or array to set node sizes
355382
"""
@@ -360,6 +387,8 @@ def clean(x, y, conn, color=None, label=None, size=None, imagedata=None):
360387

361388
outdict = add_property(outdict, color, 'color')
362389
outdict = add_property(outdict, label, 'label')
390+
outdict = add_property(outdict, value, 'value')
391+
outdict = add_property(outdict, colormap, 'colormap')
363392
outdict = add_property(outdict, size, 'size')
364393

365394
if imagedata is not None:

test/test_plots.py

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ def test_create_scatter(self, lgn):
2525
assert isinstance(viz, Visualization)
2626
assert hasattr(viz, 'id')
2727

28+
def test_create_scatter_value(self, lgn):
29+
30+
x = random.randn(100)
31+
y = random.randn(100)
32+
v = ceil(random.rand(100) * 5)
33+
s = random.rand(100) * 10 + 10
34+
a = clip(random.rand(100) + 0.1, 0, 1)
35+
36+
viz = lgn.scatter(x, y, value=v, colormap="Purples", size=s, alpha=a)
37+
38+
assert isinstance(viz, Visualization)
39+
assert hasattr(viz, 'id')
40+
2841
def test_create_line(self, lgn):
2942

3043
series = random.randn(5,100)

0 commit comments

Comments
 (0)