Skip to content

Commit 9b7c013

Browse files
authored
perf(points): strip alpha on unique colours, not once per point (#692)
1 parent 224f069 commit 9b7c013

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/spatialdata_plot/pl/render.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,11 @@ def _render_points(
13411341
and isinstance(color_vector[0], str)
13421342
and color_vector[0].startswith("#")
13431343
):
1344-
color_vector = np.asarray([_hex_no_alpha(c) for c in color_vector])
1344+
# color_vector usually holds only a few distinct hex strings (one per
1345+
# category), so strip alpha on the unique values and map back rather than
1346+
# calling the per-string parser once per point.
1347+
unique_hex, inverse = np.unique(color_vector, return_inverse=True)
1348+
color_vector = np.asarray([_hex_no_alpha(c) for c in unique_hex])[inverse]
13451349

13461350
shade_how = render_params.density_how if render_params.density else "linear"
13471351
# Plain density (no color column) must use the user-facing cmap as a sequential

0 commit comments

Comments
 (0)