Skip to content

[Bug]: tight_layout doesn't work with fixed aspect Axes #21009

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

Open
dstansby opened this issue Sep 7, 2021 · 3 comments
Open

[Bug]: tight_layout doesn't work with fixed aspect Axes #21009

dstansby opened this issue Sep 7, 2021 · 3 comments
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout

Comments

@dstansby
Copy link
Member

dstansby commented Sep 7, 2021

Bug summary

tight_layout() tries to set the x/y subplot parameters independently. When using a fixed-aspect Axes, this has issues because the x/y extents of the Axes cannot be independently set.

This is the root cause of #4251, with a much simpler example below. Also possibly a duplicate of #18313, but I thought it was worth a new issue as this one has a much simpler example.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_aspect('equal')
ax.set_ylabel('really really really really long label', rotation=0, horizontalalignment='right')

fig.tight_layout()
plt.show()

Actual outcome

Figure_1

Expected outcome

The long axis label is contained within the figure.

Operating system

macOS

Matplotlib Version

3.4.2.post1853+gdce40267b5.d20210907

Matplotlib Backend

MacOSX

Python version

3.9.6

Jupyter version

No response

Other libraries

No response

Installation

source

Conda channel

No response

@dstansby dstansby added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Sep 7, 2021
@jklymak
Copy link
Member

jklymak commented Sep 8, 2021

I'll note this works fine for constrained_layout 😉

@dstansby
Copy link
Member Author

dstansby commented Sep 8, 2021

I just gave this ago, and indeed it does work fine when I save a figure, but when I run the following code the figure window looks like this, so I think there's still an issue somewhere?:

Screenshot 2021-09-08 at 13 38 27

import matplotlib.pyplot as plt

fig, ax = plt.subplots(constrained_layout=True)
ax.set_aspect('equal')
ax.set_ylabel('really really really really long label', rotation=0, horizontalalignment='right')

plt.show()

@jklymak
Copy link
Member

jklymak commented Sep 8, 2021

Your figure looks really large. Perhaps it is interacting with your figure manager incorrectly or you have some other rcParam set? With a default figure size I get:

CL

Edit: that was Qt5Agg. I see you are using MacOSX, but I get the same result with MacOSX, just the toolbar is on the bottom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Projects
None yet
Development

No branches or pull requests

2 participants