diff --git a/lib/mpl_toolkits/mplot3d/axis3d.py b/lib/mpl_toolkits/mplot3d/axis3d.py index 0ac2e50b1a1a..a5c87c9d3cd4 100644 --- a/lib/mpl_toolkits/mplot3d/axis3d.py +++ b/lib/mpl_toolkits/mplot3d/axis3d.py @@ -722,9 +722,22 @@ def get_tightbbox(self, renderer=None, *, for_layout_only=False): other.append(self.offsetText.get_window_extent(renderer)) if self.line.get_visible(): other.append(self.line.get_window_extent(renderer)) - if (self.label.get_visible() and not for_layout_only and - self.label.get_text()): - other.append(self.label.get_window_extent(renderer)) + if self.label.get_visible() and self.label.get_text(): + bb = self.label.get_window_extent(renderer) + if for_layout_only: + if self.axis_name == "z": + if bb.height > 0: + bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5 + bb.y1 = bb.y0 + 1.0 + elif self.axis_name == "x": + if bb.width > 0: + bb.x0 = (bb.x0 + bb.x1) / 2 - 0.5 + bb.x1 = bb.x0 + 1.0 + elif self.axis_name == "y": + if bb.height > 0: + bb.y0 = (bb.y0 + bb.y1) / 2 - 0.5 + bb.y1 = bb.y0 + 1.0 + other.append(bb) return mtransforms.Bbox.union([*bb_1, *bb_2, *other])