Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ultraplot/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,10 @@ def _update_axis_label(self, side, axs):
props = ("ha", "va", "rotation", "rotation_mode")
suplab = suplabs[ax] = self.text(0, 0, "")
suplab.update({prop: getattr(axlab, "get_" + prop)() for prop in props})
# Spanning labels are positioned manually while regular axis labels are
# replaced by space placeholders to reserve bbox space. Exclude these
# figure-level labels from tight layout to avoid double counting.
suplab.set_in_layout(False)

# Copy text from the central label to the spanning label
# NOTE: Must use spaces rather than newlines, otherwise tight layout
Expand Down
23 changes: 23 additions & 0 deletions ultraplot/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,29 @@ def test_subset_share_xlabels_override():
uplt.close(fig)


def test_spanning_labels_excluded_from_tight_layout_bbox():
"""
Spanning x/y labels should not be counted twice by tight layout.

Regression test: with ``space=0``, including the figure-level spanning labels
in layout caused oversized left/bottom margins.
"""
fig, ax = uplt.subplots(space=0, refwidth="10em")
ax.format(xticks="null", yticks="null", xlabel="x axis", ylabel="y axis")
fig.canvas.draw()

assert fig._supxlabel_dict
assert fig._supylabel_dict
assert all(not lab.get_in_layout() for lab in fig._supxlabel_dict.values())
assert all(not lab.get_in_layout() for lab in fig._supylabel_dict.values())

left, bottom, _, _ = ax.get_position().bounds
assert left < 0.25
assert bottom < 0.25

uplt.close(fig)


def test_subset_share_xlabels_implicit():
fig, ax = uplt.subplots(ncols=2, nrows=2, share="labels", span=False)
ax[0, 0].format(xlabel="Top-left X")
Expand Down
Loading