Skip to content
Open
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
19 changes: 16 additions & 3 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right idea, but needs generalising. My understanding of the 2D case is that, for the layout engine, we do not want to make extra space in the direction parallel to the axis because if the label is very long you eventually just run out of space on the figure. For 2D the parallel direction is fixed for x and y so the code can explicitly mention width and height. For 3D each of x, y, and z can be in any direction.

other.append(bb)

return mtransforms.Bbox.union([*bb_1, *bb_2, *other])

Expand Down
Loading