Calling fig.tight_layout() on a figure with a 3d Axes inside will collapse the axes into a vertical line.
Minimal example:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
for tighten in False,True:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot([1,2], [1,2], [1,2])
if tighten:
fig.tight_layout()
plt.show()
The following figures are produced with python 3.7, matplotlib 3.0.0 (also master):
There's also a warning that says
/home/user/matplotlib-env/lib/python3.7/site-packages/matplotlib/tight_layout.py:177: UserWarning: The left and right margins cannot be made large enough to accommodate all axes decorations.
but that's hardly surprising since there's no room for any decorations whatsoever.
May or may not be related to the recent-ish issues fixed by #11739 and #11627.
The right spines on this axis has a very large value of x1 and is still marked as visible. tight_layout now tries to use all artists, and this sporadic artist causes tight_layout to try to make room.
Not sure where that axis position gets set. Hopefully someone familiar with the 3d code can help. I'd suggest it just get marked as not visible.
This same issue is also present in 2D plots with fig.tight_layout(). My program uses matplotlib as back-end in PyQt4. The issue occurs only if I try to use the "zoom" button from bar.
Activity
jklymak commented on Sep 23, 2018
The right spines on this axis has a very large value of x1 and is still marked as visible. tight_layout now tries to use all artists, and this sporadic artist causes tight_layout to try to make room.
Not sure where that axis position gets set. Hopefully someone familiar with the 3d code can help. I'd suggest it just get marked as not visible.
jklymak commented on Sep 23, 2018
I think #12241 fixes this without too many side effects.
xo-HADES-xo commented on Sep 24, 2018
This same issue is also present in 2D plots with fig.tight_layout(). My program uses matplotlib as back-end in PyQt4. The issue occurs only if I try to use the "zoom" button from bar.
I had to revert to 2.2.3 which fixed issue.
jklymak commented on Sep 24, 2018
@nhades It's possible to create a plot that this is an issue, but note that most plots don't have a problem. Can you open a new issue with a minimal example that triggers the axes collapse? Also, please take a look at https://matplotlib.org/api/api_changes.html#matplotlib-axes-axes-get-tightbbox-now-includes-all-artists