From 66261092b18a1960d5962605e6ae481bcb91114a Mon Sep 17 00:00:00 2001 From: Philipp Schlegel Date: Wed, 4 Dec 2024 19:33:11 +0000 Subject: [PATCH] plot3d: fix transparency issue with skeletons and plotly backend --- navis/plotting/plotly/graph_objs.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/navis/plotting/plotly/graph_objs.py b/navis/plotting/plotly/graph_objs.py index ac9f9cb9..996b7da4 100644 --- a/navis/plotting/plotly/graph_objs.py +++ b/navis/plotting/plotly/graph_objs.py @@ -462,6 +462,12 @@ def skeleton2plotly(neuron, legendgroup, showlegend, label, color, settings): coords = segments_to_coords(neuron) + # For some reason, plotly seems to ignore the alpha channel when given an RGBA color + # (the color still changes somewhat but the line doesn't turn transparent) + # Instead, we have to set the `opacity` property of the whole scatter object + # - we will adjust opacity further down if according to the color + opacity = 1 + # We have to add (None, None, None) to the end of each segment to # make that line discontinuous coords = np.vstack([np.append(t, [[None] * 3], axis=0) for t in coords]) @@ -483,6 +489,9 @@ def skeleton2plotly(neuron, legendgroup, showlegend, label, color, settings): ] else: + if len(color) == 4: + opacity = color[3] + c = f"rgb({color[0]},{color[1]},{color[2]})" if settings.hover_id: @@ -506,6 +515,7 @@ def skeleton2plotly(neuron, legendgroup, showlegend, label, color, settings): x=coords[:, 0], y=coords[:, 1], z=coords[:, 2], + opacity=opacity, mode="lines", line=dict(color=c, width=settings.get('linewidth', 3), dash=dash), name=label,