You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: The zlabel on 3D axes will be cut when using '%matplotlib inline' in Jupyter #28117
So something like this fixes it, but I'm not sure it's right:
diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py
index d5b8631e95..101880c027 100644
--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -1405,7 +1405,7 @@ def _get_tightbbox_for_layout_only(obj, *args, **kwargs):
when encountering third-party subclasses that do not support it.
"""
try:
- return obj.get_tightbbox(*args, **{**kwargs, "for_layout_only": True})+ return obj.get_tightbbox(*args, **{"for_layout_only": True, **kwargs})
except TypeError:
return obj.get_tightbbox(*args, **kwargs)
diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py
index 12f3682ae5..5895b22353 100644
--- a/lib/mpl_toolkits/mplot3d/axes3d.py+++ b/lib/mpl_toolkits/mplot3d/axes3d.py@@ -3769,7 +3769,7 @@ class Axes3D(Axes):
for axis in self._axis_map.values():
if axis.get_visible():
axis_bb = martist._get_tightbbox_for_layout_only(
- axis, renderer)+ axis, renderer, for_layout_only=for_layout_only)
if axis_bb:
batch.append(axis_bb)
return mtransforms.Bbox.union(batch)
i.e., I don't know why this only affects the Z label, and there's probably a different bug with it that's the real cause. And additionally, as noted above, this changed for regular Axes without breakage, nor needing to revert it to fix this bug, so there's something specifically fishy about for_layout_only=True for the Z label only.
A possibility on why it seems to only affect Z is that by default, the Z
axis is parallel to an edge of the bounding box, while X and Y axis are
not. The X and Y labels might be ending up inside the tight bbox anyway.
On Mon, Jul 8, 2024 at 9:08 PM Elliott Sales de Andrade < ***@***.***> wrote:
So something like this fixes it, but I'm not sure it's right:
diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py
index d5b8631e95..101880c027 100644--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -1405,7 +1405,7 @@ def _get_tightbbox_for_layout_only(obj, *args, **kwargs):
when encountering third-party subclasses that do not support it.
"""
try:- return obj.get_tightbbox(*args, **{**kwargs, "for_layout_only": True})+ return obj.get_tightbbox(*args, **{"for_layout_only": True, **kwargs})
except TypeError:
return obj.get_tightbbox(*args, **kwargs)
diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py
index 12f3682ae5..5895b22353 100644--- a/lib/mpl_toolkits/mplot3d/axes3d.py+++ b/lib/mpl_toolkits/mplot3d/axes3d.py@@ -3769,7 +3769,7 @@ class Axes3D(Axes):
for axis in self._axis_map.values():
if axis.get_visible():
axis_bb = martist._get_tightbbox_for_layout_only(- axis, renderer)+ axis, renderer, for_layout_only=for_layout_only)
if axis_bb:
batch.append(axis_bb)
return mtransforms.Bbox.union(batch)
i.e., I don't know why this only affects the Z label, and there's probably
a different bug with it that's the *real* cause. And additionally, as
noted above, this changed for regular Axes without breakage, nor needing
to revert it to fix this bug, so there's something specifically fishy about
for_layout_only=True for the Z label only.
—
Reply to this email directly, view it on GitHub
<#28117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6BBKJOZO5KYXEFOZWTZLMZYBAVCNFSM6AAAAABGSTBA4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJVHE2DGMJSGI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
This works, but I'm not sure it's any better than explicitly handling the for_layout_only=False case in Axes[3D].get_tightbbox, as #31571 is doing for 3D.
diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py
index 88e38634b5..12fcb58950 100644
--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -1475,14 +1475,14 @@ Supported properties are
mouseover = property(get_mouseover, set_mouseover) # backcompat.
--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -1475,14 +1475,14 @@ Supported properties are
mouseover = property(get_mouseover, set_mouseover) # backcompat.
-def _get_tightbbox_for_layout_only(obj, *args, **kwargs):+def _get_tightbbox_for_layout_only(obj, *args, for_layout_only=True, **kwargs):
"""
Matplotlib's `.Axes.get_tightbbox` and `.Axis.get_tightbbox` support a
*for_layout_only* kwarg; this helper tries to use the kwarg but skips it
when encountering third-party subclasses that do not support it.
"""
try:
- return obj.get_tightbbox(*args, **{**kwargs, "for_layout_only": True})+ return obj.get_tightbbox(*args, for_layout_only=for_layout_only, **kwargs)
except TypeError:
return obj.get_tightbbox(*args, **kwargs)
diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py
index ee933ea138..aac92863f3 100644
--- a/lib/matplotlib/axes/_base.py+++ b/lib/matplotlib/axes/_base.py@@ -4705,7 +4705,8 @@ class _AxesBase(martist.Artist):
for axis in self._axis_map.values():
if self.axison and axis.get_visible():
- ba = martist._get_tightbbox_for_layout_only(axis, renderer)+ ba = martist._get_tightbbox_for_layout_only(+ axis, renderer, for_layout_only=for_layout_only)
if ba:
bb.append(ba)
self._update_title_position(renderer)
diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py
index 45f9319355..ed1588960e 100644
--- a/lib/mpl_toolkits/mplot3d/axes3d.py+++ b/lib/mpl_toolkits/mplot3d/axes3d.py@@ -4165,7 +4165,7 @@ class Axes3D(Axes):
for axis in self._axis_map.values():
if axis.get_visible():
axis_bb = martist._get_tightbbox_for_layout_only(
- axis, renderer)+ axis, renderer, for_layout_only=for_layout_only)
if axis_bb:
batch.append(axis_bb)
return mtransforms.Bbox.union(batch)
Activity
QuLogic commentedon Jul 8, 2024
This bisects to 5c75807.
QuLogic commentedon Jul 9, 2024
I think the issue is that previously, we passed
for_layout_onlythrough from the caller forAxesand forAxes3D.But the new helper always uses
for_layout_only=True.For whatever reason, this produces a different result for the Z label only:
QuLogic commentedon Jul 9, 2024
So something like this fixes it, but I'm not sure it's right:
i.e., I don't know why this only affects the Z label, and there's probably a different bug with it that's the real cause. And additionally, as noted above, this changed for regular
Axeswithout breakage, nor needing to revert it to fix this bug, so there's something specifically fishy aboutfor_layout_only=Truefor the Z label only.WeatherGod commentedon Jul 9, 2024
QuLogic commentedon Jul 9, 2024
It looks like for X/Y, we flatten the label bbox in the long direction:
matplotlib/lib/matplotlib/axis.py
Lines 1386 to 1398 in 0fd212d
but for Z, we ignore it entirely:
matplotlib/lib/mpl_toolkits/mplot3d/axis3d.py
Lines 723 to 725 in 0fd212d
We should probably harmonize that, though the question will be whether we can do so for all rotations and/or vertical axis settings.
chiavez commentedon Mar 26, 2026
Same problem here, i had to manually add the label by using:
Generally, the bounding boxes for 3D plots are buggy. There is either too much white space (#19519) or too little.
FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping
asyncgit: include 3D axis labels in get_tightbbox when not for_layout…
FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping
rcomer commentedon Apr 28, 2026
I actually think we also have a problem for 2D
Shouldn't the figure expand to fit the label? [Edit: confirmed that it did in v3.5]
rcomer commentedon Apr 28, 2026
This works, but I'm not sure it's any better than explicitly handling the
for_layout_only=Falsecase inAxes[3D].get_tightbbox, as #31571 is doing for 3D.FIX: Include axis labels in Axes3D.get_tightbbox() to prevent clipping
Fix 3D axis labels excluded from tightbbox (closes matplotlib#28117)