Bug summary
savefig(bbox_inches='tight') clips the zlabel and xlabel on 3D axes. This happens because Axes3D.get_tightbbox() does not include axis labels in its bounding box calculation. On 2D axes this works correctly.
Code for reproduction
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(3, 3))
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot([0, 1], [0, 1], [0, 1])
ax.set_zlabel("Z axis label")
ax.set_xlabel("X axis label")
fig.savefig("3d_tight.png", bbox_inches='tight')
Actual outcome
zlabel and xlabel are clipped at the edges of the saved image.
Confirmed numerically:
tightbbox: x1=296.0
zlabel x1=321.2 → 25px outside tightbbox on the right
xlabel y0=1.0 → 12px outside tightbbox at the bottom
Expected outcome
Expected outcome
Labels should be fully visible, as they are when saving without`
`.
On 2D axes, get_tightbbox() always includes xlabel tightbbox.y0 == xlabel.y0. On 3D it does not.
Additional information
Related to the broader known issue of 3D axes not fully contributing to bounding box calculations, noted by @QuLogic in #31277. This specific symptom axis labels excluded from get_tightbbox() produces a concrete user-visible artifact in saved figures.
Operating system
No response
Matplotlib Version
3.10.8
Matplotlib Backend
Agg
Python version
No response
Jupyter version
No response
Installation
pip
Bug summary
savefig(bbox_inches='tight')clips thezlabelandxlabelon 3D axes. This happens becauseAxes3D.get_tightbbox()does not include axis labels in its bounding box calculation. On 2D axes this works correctly.Code for reproduction
Actual outcome
zlabelandxlabelare clipped at the edges of the saved image.Confirmed numerically:
Expected outcome
Expected outcome
Labels should be fully visible, as they are when saving without`
`.
On 2D axes,
get_tightbbox() always includes xlabeltightbbox.y0 == xlabel.y0. On 3D it does not.Additional information
Related to the broader known issue of 3D axes not fully contributing to bounding box calculations, noted by @QuLogic in #31277. This specific symptom axis labels excluded from
get_tightbbox()produces a concrete user-visible artifact in saved figures.Operating system
No response
Matplotlib Version
3.10.8
Matplotlib Backend
Agg
Python version
No response
Jupyter version
No response
Installation
pip