Skip to content

Commit 75d1b3a

Browse files
committed
Set axes zorder at creation
Pass the owning plot's _zorder to add_subplot in facet._make_axes so every panel axes is born at the right layer. Compose.draw propagates the composition's _zorder to its direct children before drawing, and the recursion carries the value down sub-compositions. Combined with ggplot._draw_insets raising _zorder by 1 per inset boundary, insets (including Compose insets and nested insets) end up above the host without any post-hoc subtree walk.
1 parent 9a5f094 commit 75d1b3a

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

plotnine/composition/_compose.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@ def draw(self, *, show: bool = False) -> Figure:
549549

550550
def _draw(cmp):
551551
figure = cmp._setup()
552+
553+
# Propagate the composition's zorder to its direct children
554+
# before they draw, so axes are created at the right layer.
555+
# Recursion carries the value down sub-compositions.
556+
for item in cmp:
557+
item._zorder = cmp._zorder
558+
552559
cmp._draw_plots()
553560

554561
for sub_cmp in cmp.iter_sub_compositions():

plotnine/facets/facet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ def _make_axes(self) -> tuple[p9GridSpec, list[Axes]]:
399399
# Create axes
400400
it = itertools.product(range(self.nrow), range(self.ncol))
401401
for i, (row, col) in enumerate(it):
402-
axsarr[row, col] = self.figure.add_subplot(gs[i])
402+
axsarr[row, col] = self.figure.add_subplot(
403+
gs[i], zorder=self.plot._zorder
404+
)
403405

404406
# Rearrange axes
405407
# They are ordered to match the positions in the layout table

0 commit comments

Comments
 (0)