diff --git a/ultraplot/axes/base.py b/ultraplot/axes/base.py index f9624d64a..d99248e67 100644 --- a/ultraplot/axes/base.py +++ b/ultraplot/axes/base.py @@ -3429,6 +3429,8 @@ def format( return if rc_mode == 1: # avoid resetting return + if self._inset_parent is not None or self._panel_parent is not None: + return self.figure.format(rc_kw=rc_kw, rc_mode=rc_mode, skip_axes=True, **params) def draw(self, renderer=None, *args, **kwargs): diff --git a/ultraplot/tests/test_axes.py b/ultraplot/tests/test_axes.py index e59d5ac9f..f1fad637a 100644 --- a/ultraplot/tests/test_axes.py +++ b/ultraplot/tests/test_axes.py @@ -616,3 +616,46 @@ def test_alt_axes_x_shared(): assert alt.get_ylabel() == "" axi.set_xlabel("X") return fig + + +def test_inset_format_scope(): + """ + Test that calling format() on an inset axes does not affect the + parent figure's properties like suptitle or super labels. + """ + fig, axs = uplt.subplots() + ax = axs[0] + # Inset axes are instances of the same class as the parent + ix = ax.inset_axes([0.5, 0.5, 0.4, 0.4]) + assert ix._inset_parent is ax, "Inset parent should be the main axes" + + # Test that suptitle is not set + ix.format(suptitle="This should not appear") + assert ( + fig._suptitle is None or fig._suptitle.get_text() == "" + ), "Inset format should not set the figure's suptitle." + + # Test that leftlabels are not set + # Create a copy to ensure we're not comparing against a modified list + original_left_labels = list(fig._suplabel_dict["left"]) + ix.format(leftlabels=["a", "b"]) + assert ( + list(fig._suplabel_dict["left"]) == original_left_labels + ), "Inset format should not set the figure's leftlabels." + + +def test_panel_format_scope(): + """ + Test that calling format() on a panel axes does not affect the + parent figure's properties like suptitle. + """ + fig, axs = uplt.subplots() + ax = axs[0] + pax = ax.panel_axes("right") + assert pax._panel_parent is ax, "Panel parent should be the main axes" + + # Test that suptitle is not set + pax.format(suptitle="This should not appear") + assert ( + fig._suptitle is None or fig._suptitle.get_text() == "" + ), "Panel format should not set the figure's suptitle."