@@ -27,6 +27,7 @@ def __init__(
2727 z_position : Union [List [float ], float ] = None ,
2828 thickness : Union [float , List [float ]] = 2.0 ,
2929 colors : Union [List [np .ndarray ], np .ndarray ] = "w" ,
30+ alpha : float = 1.0 ,
3031 cmap : Union [List [str ], str ] = None ,
3132 name : str = None ,
3233 * args ,
@@ -131,33 +132,44 @@ def __init__(
131132 "with the same length as the data" )
132133 else :
133134 if isinstance (colors , np .ndarray ):
135+ # single color for all lines in the collection as RGBA
134136 if colors .shape == (4 ,):
135137 single_color = True
136138
139+ # colors specified for each line as array of shape [n_lines, RGBA]
137140 elif colors .shape == (len (data ), 4 ):
138141 single_color = False
139142
140143 else :
141144 raise ValueError (
142- "numpy array colors argument must be of shape (4,) or (len(data), 4)"
145+ f"numpy array colors argument must be of shape (4,) or (n_lines, 4)."
146+ f"You have pass the following shape: { colors .shape } "
143147 )
144148
145149 elif isinstance (colors , str ):
146- single_color = True
147- colors = pygfx .Color (colors )
150+ if colors == "random" :
151+ colors = np .random .rand (len (data ), 4 )
152+ colors [:, - 1 ] = alpha
153+ single_color = False
154+ else :
155+ # parse string color
156+ single_color = True
157+ colors = pygfx .Color (colors )
148158
149159 elif isinstance (colors , (tuple , list )):
150160 if len (colors ) == 4 :
161+ # single color specified as (R, G, B, A) tuple or list
151162 if all ([isinstance (c , (float , int )) for c in colors ]):
152163 single_color = True
153164
154165 elif len (colors ) == len (data ):
166+ # colors passed as list/tuple of colors, such as list of string
155167 single_color = False
156168
157169 else :
158170 raise ValueError (
159171 "tuple or list colors argument must be a single color represented as [R, G, B, A], "
160- "or must be a str of tuple/list with the same length as the data"
172+ "or must be a tuple/list of colors represented by a string with the same length as the data"
161173 )
162174
163175 self ._set_world_object (pygfx .Group ())
0 commit comments