Skip to content
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

3d axes are collapsed by tight_layout #12239

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
Labels
Milestone

Comments

@adeak
Copy link
Contributor

@adeak 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

This comment has been minimized.

Copy link
Contributor

@jklymak 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 jklymak mentioned this issue Sep 23, 2018
0 of 6 tasks complete
@jklymak

This comment has been minimized.

Copy link
Contributor

@jklymak jklymak commented Sep 23, 2018

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

@dstansby dstansby added the mplot3d label Sep 24, 2018
@jklymak jklymak added this to the v3.0.x milestone Sep 24, 2018
@NHades

This comment has been minimized.

Copy link

@NHades NHades 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

This comment has been minimized.

Copy link
Contributor

@jklymak 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
4 participants
You can’t perform that action at this time.