Skip to content

3d axes are collapsed by tight_layout #12239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adeak opened this issue Sep 23, 2018 · 4 comments · Fixed by #12241
Closed

3d axes are collapsed by tight_layout #12239

adeak opened this issue Sep 23, 2018 · 4 comments · Fixed by #12241
Milestone

Comments

@adeak
Copy link
Contributor

adeak commented Sep 23, 2018

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):
figure without tight_layout: all's fine
figure with tight_layout: axes is a single vertical line

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.

@jklymak
Copy link
Member

jklymak commented 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
Copy link
Member

jklymak commented Sep 23, 2018

I think #12241 fixes this without too many side effects.

@jklymak jklymak added this to the v3.0.x milestone Sep 24, 2018
@xo-HADES-xo
Copy link

xo-HADES-xo commented 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
Copy link
Member

jklymak commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants