Skip to content

Commit

Permalink
plot3d: fix transparency issue with skeletons and plotly backend
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Dec 4, 2024
1 parent 61e76db commit 6626109
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions navis/plotting/plotly/graph_objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit 6626109

Please sign in to comment.