diff --git a/src/spatialdata_plot/pl/render.py b/src/spatialdata_plot/pl/render.py index 708ba305..b66ebc7e 100644 --- a/src/spatialdata_plot/pl/render.py +++ b/src/spatialdata_plot/pl/render.py @@ -1341,7 +1341,11 @@ def _render_points( and isinstance(color_vector[0], str) and color_vector[0].startswith("#") ): - color_vector = np.asarray([_hex_no_alpha(c) for c in color_vector]) + # color_vector usually holds only a few distinct hex strings (one per + # category), so strip alpha on the unique values and map back rather than + # calling the per-string parser once per point. + unique_hex, inverse = np.unique(color_vector, return_inverse=True) + color_vector = np.asarray([_hex_no_alpha(c) for c in unique_hex])[inverse] shade_how = render_params.density_how if render_params.density else "linear" # Plain density (no color column) must use the user-facing cmap as a sequential