Skip to content

Commit b290bcd

Browse files
committed
Background wraps the user bbox for image insets
The background rectangle on an image inset now tracks the full user bbox (the letterbox envelope) instead of the fitted image. A themed fill or border now surrounds the whole requested region, with the fill visible in the letterbox padding bands. The patch is now added before the image artist so its fill renders behind the image; previously it sat on top because it hugged the image and only the border was meant to be visible.
1 parent d071c64 commit b290bcd

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

plotnine/composition/_inset_image.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ def _arrange_in_box(
9595
9696
The image is letterboxed inside the box with transparent
9797
padding on the two opposing edges, positioned by the
98-
configured `anchor`. The background rectangle tracks the
99-
same fitted box.
98+
configured `anchor`. The background rectangle wraps the full
99+
user bbox (the letterbox envelope), so a themed fill or
100+
border surrounds the entire requested region — not just the
101+
fitted image.
100102
101103
Parameters
102104
----------
@@ -113,22 +115,24 @@ def _arrange_in_box(
113115
self.figure,
114116
anchor=self._anchor,
115117
)
116-
w, h = r - l, t - b
117-
self._frac_bbox.bounds = (l, b, w, h) # pyright: ignore[reportAttributeAccessIssue]
118-
self.patch.set_bounds(l, b, w, h)
118+
self._frac_bbox.bounds = (l, b, r - l, t - b) # pyright: ignore[reportAttributeAccessIssue]
119+
self.patch.set_bounds(left, bottom, right - left, top - bottom)
119120

120121
def draw(self):
121122
from matplotlib.image import BboxImage
122123
from matplotlib.transforms import TransformedBbox
123124

125+
# Background first so its fill sits behind the image — the
126+
# letterbox.
127+
self.theme._setup(self) # pyright: ignore[reportArgumentType]
128+
self._draw_plot_background()
129+
124130
image_artist = BboxImage(
125131
TransformedBbox(self._frac_bbox, self.figure.transFigure)
126132
)
127133
image_artist.set_data(np.asarray(self._image))
128134
self.figure.add_artist(image_artist)
129135

130-
self.theme._setup(self) # pyright: ignore[reportArgumentType]
131-
self._draw_plot_background()
132136
self.theme.apply()
133137

134138
def _draw_plot_background(self):

0 commit comments

Comments
 (0)