diff --git a/ultraplot/axes/base.py b/ultraplot/axes/base.py index 416b33430..f72dea8a8 100644 --- a/ultraplot/axes/base.py +++ b/ultraplot/axes/base.py @@ -1347,22 +1347,24 @@ def shared(paxs): # External axes sharing, sometimes overrides panel axes sharing # Share x axes within compatible groups - axes_x = self._get_share_axes("x") - for group in self.figure._partition_share_axes(axes_x, "x"): - if not group: - continue - parent, *children = group - for child in children: - child._sharex_setup(parent) + if self.figure._sharex > 0: + axes_x = self._get_share_axes("x") + for group in self.figure._partition_share_axes(axes_x, "x"): + if not group: + continue + parent, *children = group + for child in children: + child._sharex_setup(parent) # Share y axes within compatible groups - axes_y = self._get_share_axes("y") - for group in self.figure._partition_share_axes(axes_y, "y"): - if not group: - continue - parent, *children = group - for child in children: - child._sharey_setup(parent) + if self.figure._sharey > 0: + axes_y = self._get_share_axes("y") + for group in self.figure._partition_share_axes(axes_y, "y"): + if not group: + continue + parent, *children = group + for child in children: + child._sharey_setup(parent) # Global sharing, use the reference subplot where compatible ref = self.figure._subplot_dict.get(self.figure._refnum, None) diff --git a/ultraplot/figure.py b/ultraplot/figure.py index 334c61a44..59646d1cd 100644 --- a/ultraplot/figure.py +++ b/ultraplot/figure.py @@ -1325,6 +1325,15 @@ def _share_ticklabels(self, *, axis: str) -> None: # Process each group independently for _, group_axes in groups.items(): + # Nothing to share if the group is too small or sharing is disabled — + # avoids unsupported-type warnings (e.g. PolarAxes) for those cases. + if len(group_axes) < 2: + continue + if all( + self._effective_share_level(axi, axis, sides) < 3 for axi in group_axes + ): + continue + # Build baseline from MAIN axes only (exclude panels) baseline, skip_group = self._compute_baseline_tick_state( group_axes, axis, label_keys diff --git a/ultraplot/tests/test_figure.py b/ultraplot/tests/test_figure.py index a78ac0402..6ae668c4f 100644 --- a/ultraplot/tests/test_figure.py +++ b/ultraplot/tests/test_figure.py @@ -354,6 +354,56 @@ def test_explicit_share_warns_for_mixed_cartesian_polar(): assert len(incompatible) == 1 +def test_share_zero_polar_emits_no_warnings(recwarn): + fig, axs = uplt.subplots(proj="polar", ncols=2, nrows=3, share=0) + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_zero_mixed_cartesian_polar_emits_no_warnings(recwarn): + fig, axs = uplt.subplots(ncols=2, proj=("cart", "polar"), share=0) + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_default_single_polar_emits_no_warnings(recwarn): + """A single polar axis has nothing to share — must not warn at default share.""" + fig, ax = uplt.subplots(proj="polar") + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + +def test_share_default_single_polar_subplot_singular_emits_no_warnings(recwarn): + """``uplt.subplot(proj='polar')`` (singular) has nothing to share either.""" + fig, ax = uplt.subplot(proj="polar") + fig.canvas.draw() + + ultra = [ + w + for w in recwarn + if issubclass(w.category, uplt.internals.warnings.UltraPlotWarning) + ] + assert ultra == [], [str(w.message) for w in ultra] + + def test_auto_share_local_yscale_change_splits_group(): fig, axs = uplt.subplots(ncols=2, share="auto") fig.canvas.draw()