Skip to content

Commit d6becd6

Browse files
committed
Stop applying colorbar alpha twice (#687)
`fig.colorbar(mappable)` already bakes the mappable's alpha into the colorbar's QuadMesh facecolors (verified: alpha column = mappable.alpha straight after construction). Our subsequent `cb.solids.set_alpha(spec.alpha)` then multiplied on top, so the colorbar rendered at alpha squared and looked much paler than the layer it represents. Only apply `spec.alpha` when the mappable does not carry alpha of its own; if it does, trust the inherited value. Visible improvement on every continuous-color colorbar (especially labels at low fill_alpha, e.g. `Labels_can_handle_dropping_small_labels_after_rasterize_continuous` and `Labels_two_calls_with_coloring_result_in_two_colorbars`).
1 parent e459dfa commit d6becd6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/spatialdata_plot/pl/basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,11 @@ def _draw_colorbar(
16371637
final_label = global_label_override or layer_label_override or spec.label
16381638
if final_label:
16391639
cb.set_label(final_label)
1640-
if spec.alpha is not None:
1640+
# `fig.colorbar(mappable)` already bakes the mappable's alpha into the colorbar's
1641+
# facecolors, so we only apply `spec.alpha` when the mappable carries no alpha of its own
1642+
# — otherwise we'd multiply alpha twice and the colorbar would render at alpha squared
1643+
# (much paler than the layer it represents).
1644+
if spec.alpha is not None and spec.mappable.get_alpha() is None:
16411645
with contextlib.suppress(Exception):
16421646
cb.solids.set_alpha(spec.alpha)
16431647

0 commit comments

Comments
 (0)