You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Per-panel colorbars/legends overflow into neighbouring panels in multi-panel plots #687
In multi-panel figures (multiple coordinate systems, or scanpy-style color=[...]), each panel's colorbar/legend is drawn outside the panel via inset_axes anchored to the right of ax.transAxes. When panels get small (grids, constrained canvases), the colorbar/legend — and especially its tick labels — spill into the adjacent panel.
This is most visible when several panels each carry their own colorbar (continuous) or legend (categorical): the left panel's colorbar collides with the right panel's y-axis labels.
Root cause
_draw_colorbar in pl/basic.py places the colorbar with:
i.e. outside the panel's cell. No layout engine reserves that space, so it overflows the neighbour. Categorical legends are similarly placed in the right margin.
How scanpy avoids this
scanpy reserves the colorbar/legend space inside each panel's own cell (steals from the axes), so it can never overflow:
Continuous: plt.colorbar(cax, ax=ax, pad=0.01, fraction=0.08, aspect=30, location=...) — ax=ax shrinks the panel and places the colorbar in the reclaimed space.
Categorical (multi-panel): shrink the axis first, then add the legend in the freed space:
Switch the colorbar subsystem to space-stealing plt.colorbar(ax=ax, location=, fraction=, pad=) and adopt the shrink-then-place pattern for categorical legends. This makes both single- and multi-panel layouts robust at any figure size.
Note: library-wide rendering change — affects every colorbar/legend and requires regenerating a large set of visual baselines. Preserve the existing public knobs (location left/right/top/bottom, colorbar_params, same-side stacking, alpha, label).
Discovered while implementing #611 (multi-panel color=[...]).
Activity
Regenerate colorbar baselines after space-stealing placement (#687)
Fix per-panel colorbars overflowing into neighbouring panels (#687)
Regenerate colorbar baselines for divider-based placement (#687)
Clear panel axis decorations for left/top/bottom colorbars (#687)
Use relative colorbar size to minimize baseline churn (#687)
Keep relative pad for colorbar sides without decorations (#687)
Regenerate left/top/bottom and stacked colorbar baselines (#687)
Update multipolygons baseline for divider colorbar (#687)
Pad stacked colorbars past the previous one's measured extent (#687)
Regenerate stacked colorbar baselines for measured pad (#687)
Update stale stacked-colorbar baseline for two_calls_with_coloring (#687
Stop applying colorbar alpha twice (#687)