|
86 | 86 | # once https://github.com/scverse/spatialdata/pull/689/ is in a release |
87 | 87 | ColorLike = tuple[float, ...] | list[float] | str |
88 | 88 |
|
| 89 | +# Below this clearance (inches), a colorbar side is treated as having no axis decorations to clear, |
| 90 | +# so the colorbar keeps its relative pad (matching the historical placement) instead of an absolute one. |
| 91 | +_CBAR_DECORATION_EPS_INCHES = 0.05 |
| 92 | + |
89 | 93 |
|
90 | 94 | @register_spatial_data_accessor("pl") |
91 | 95 | class PlotAccessor: |
@@ -1566,13 +1570,23 @@ def _draw_colorbar( |
1566 | 1570 | # side is padded past the panel's own decorations (ticks/labels/title) plus the requested |
1567 | 1571 | # pad; each subsequent one uses an absolute pad wide enough to clear the previous |
1568 | 1572 | # colorbar's tick labels instead of overlapping them. |
| 1573 | + # Sides with no decorations to clear (typically "right") keep the relative pad, which |
| 1574 | + # matches the historical placement; sides whose ticks/labels/title must be cleared |
| 1575 | + # (left/top/bottom), and stacked colorbars, use an absolute pad in inches. |
1569 | 1576 | n_on_side = side_counts.get(location, 0) |
1570 | 1577 | ref_in = axes_size_in[0] if location in {"left", "right"} else axes_size_in[1] |
1571 | | - pad_in = CBAR_STACK_PAD_INCHES if n_on_side else clearance.get(location, 0.0) + max(pad, 0.0) * ref_in |
| 1578 | + side_clearance = clearance.get(location, 0.0) |
| 1579 | + pad_spec: str | Fixed |
| 1580 | + if n_on_side: |
| 1581 | + pad_spec = Fixed(CBAR_STACK_PAD_INCHES) |
| 1582 | + elif side_clearance > _CBAR_DECORATION_EPS_INCHES: |
| 1583 | + pad_spec = Fixed(side_clearance + max(pad, 0.0) * ref_in) |
| 1584 | + else: |
| 1585 | + pad_spec = f"{max(pad, 0.0) * 100}%" |
1572 | 1586 | cax = divider.append_axes( |
1573 | 1587 | location, |
1574 | 1588 | size=f"{max(fraction, 0.0) * 100}%", |
1575 | | - pad=Fixed(pad_in), |
| 1589 | + pad=pad_spec, |
1576 | 1590 | axes_class=Axes, |
1577 | 1591 | ) |
1578 | 1592 | side_counts[location] = n_on_side + 1 |
|
0 commit comments