Skip to content

Commit 56e7458

Browse files
authored
Fix: Isolate inset and panel format from figure format (#486)
1 parent 5a5a754 commit 56e7458

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ultraplot/axes/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,8 @@ def format(
34293429
return
34303430
if rc_mode == 1: # avoid resetting
34313431
return
3432+
if self._inset_parent is not None or self._panel_parent is not None:
3433+
return
34323434
self.figure.format(rc_kw=rc_kw, rc_mode=rc_mode, skip_axes=True, **params)
34333435

34343436
def draw(self, renderer=None, *args, **kwargs):

ultraplot/tests/test_axes.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,46 @@ def test_alt_axes_x_shared():
616616
assert alt.get_ylabel() == ""
617617
axi.set_xlabel("X")
618618
return fig
619+
620+
621+
def test_inset_format_scope():
622+
"""
623+
Test that calling format() on an inset axes does not affect the
624+
parent figure's properties like suptitle or super labels.
625+
"""
626+
fig, axs = uplt.subplots()
627+
ax = axs[0]
628+
# Inset axes are instances of the same class as the parent
629+
ix = ax.inset_axes([0.5, 0.5, 0.4, 0.4])
630+
assert ix._inset_parent is ax, "Inset parent should be the main axes"
631+
632+
# Test that suptitle is not set
633+
ix.format(suptitle="This should not appear")
634+
assert (
635+
fig._suptitle is None or fig._suptitle.get_text() == ""
636+
), "Inset format should not set the figure's suptitle."
637+
638+
# Test that leftlabels are not set
639+
# Create a copy to ensure we're not comparing against a modified list
640+
original_left_labels = list(fig._suplabel_dict["left"])
641+
ix.format(leftlabels=["a", "b"])
642+
assert (
643+
list(fig._suplabel_dict["left"]) == original_left_labels
644+
), "Inset format should not set the figure's leftlabels."
645+
646+
647+
def test_panel_format_scope():
648+
"""
649+
Test that calling format() on a panel axes does not affect the
650+
parent figure's properties like suptitle.
651+
"""
652+
fig, axs = uplt.subplots()
653+
ax = axs[0]
654+
pax = ax.panel_axes("right")
655+
assert pax._panel_parent is ax, "Panel parent should be the main axes"
656+
657+
# Test that suptitle is not set
658+
pax.format(suptitle="This should not appear")
659+
assert (
660+
fig._suptitle is None or fig._suptitle.get_text() == ""
661+
), "Panel format should not set the figure's suptitle."

0 commit comments

Comments
 (0)