Skip to content

Commit aa8c8d5

Browse files
committed
add color argument to neuron2gfx + minor formatting
1 parent bb74918 commit aa8c8d5

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

navis/plotting/pygfx/objects.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class GfxPlotter(Plotter):
121121
"volume_legend",
122122
}
123123
BACKEND = "pygfx"
124-
124+
125125
def plot(self):
126126
"""Generate the plot."""
127127
colors = self.kwargs.get('color', None)
@@ -138,18 +138,18 @@ def plot(self):
138138
)
139139

140140

141-
# Generate scene
141+
# Generate scene
142142
scene = gfx.Group()
143143
scene.add(*neuron2gfx(core.NeuronList(self.neurons), **self.kwargs))
144144
scene.add(*volume2gfx(self.volumes, **self.kwargs))
145145
scene.add(*points2gfx(self.points, **self.kwargs))
146146

147-
# Add background
147+
# Add background
148148
scene.add(
149149
gfx.Background(material=gfx.BackgroundMaterial([0, 0, 0]))
150150
)
151151

152-
# Add light
152+
# Add light
153153
scene.add(gfx.AmbientLight())
154154
scene.add(gfx.DirectionalLight())
155155

@@ -167,15 +167,13 @@ def plot(self):
167167
controller=controller,
168168
camera=camera,
169169
renderer=renderer)
170-
#draw_function=lambda : poll_for_input(renderer, scene, camera))
170+
#draw_function=lambda : poll_for_input(renderer, scene, camera))
171171
#disp = gfx.Display() # (camera=camera)
172172
#disp.show(scene)
173173

174174

175175
#def poll_for_input(renderer, scene, camera):
176176
# renderer.render(scene, camera)
177-
178-
179177

180178

181179
def volume2gfx(x, **kwargs):
@@ -235,7 +233,7 @@ def volume2gfx(x, **kwargs):
235233
return visuals
236234

237235

238-
def neuron2gfx(x, **kwargs):
236+
def neuron2gfx(x, color=None, **kwargs):
239237
"""Convert a Neuron/List to pygfx visuals.
240238
241239
Parameters
@@ -291,7 +289,7 @@ def neuron2gfx(x, **kwargs):
291289
else:
292290
raise TypeError(f'Unable to process data of type "{type(x)}"')
293291

294-
colors = kwargs.get("color", kwargs.get("c", kwargs.get("colors", None)))
292+
colors = color if color is not None else kwargs.get("c", kwargs.get("colors", None))
295293
palette = kwargs.get("palette", None)
296294
color_by = kwargs.get("color_by", None)
297295
shade_by = kwargs.get("shade_by", None)
@@ -577,9 +575,9 @@ def skeleton2gfx(neuron, neuron_color, object_id, **kwargs):
577575
if neuron_color.ndim == 1:
578576
coords = segments_to_coords(neuron, neuron.segments)
579577
else:
580-
coords, vertex_colors = segments_to_coords(neuron, neuron.segments, node_colors=neuron_color)
581-
# `neuron_color` is now a list of colors for each segment; we have to flatten it
582-
# and add `None` to match the breaks
578+
coords, vertex_colors = segments_to_coords(neuron, neuron.segments, node_colors=neuron_color)
579+
# `neuron_color` is now a list of colors for each segment; we have to flatten it
580+
# and add `None` to match the breaks
583581
vertex_colors = np.vstack([np.append(t, [[None] * t.shape[1]], axis=0) for t in vertex_colors]).astype(np.float32, copy=False)
584582

585583
coords = np.vstack([np.append(t, [[None] * 3], axis=0) for t in coords])

0 commit comments

Comments
 (0)