Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tight_layout puts axes title below twiny xlabel #5474

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
anntzer opened this issue Nov 13, 2015 · 14 comments
Closed

tight_layout puts axes title below twiny xlabel #5474

anntzer opened this issue Nov 13, 2015 · 14 comments
Labels
topic: geometry manager LayoutEngine, Constrained layout, Tight layout
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Nov 13, 2015

plt.title("title")
plt.gca().twiny().set_xlabel("xlabel")
plt.tight_layout()

tight_twiny
matplotlib 1.5.0.

@tacaswell
Copy link
Member

Is this a regression from 1.4.3?

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Nov 13, 2015
@tacaswell
Copy link
Member

I suspect the problem here is that the title is attached to the first axes, but the axis label is attached to the twin.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 13, 2015

1.4.3 suffers from the same issue.

@tacaswell
Copy link
Member

I know it maybe annoying to users, but I am currently much more worried about regressions (ie things we broke between 1.4.3 and 1.5.0) than long standing bugs.

@WeatherGod
Copy link
Member

This is going to be a tough one to solve. Technically speaking, there is no
bug here. tight_layout() is doing exactly what it is supposed to do. The
problem is that the xlabel text object has a position relative to the
x-axis, while the title has a position defined relative to the edge of the
subplot region. These two positions are only loosely related to each other,
and there is certainly no constraint system in place to enforce relative
positions from each other.

On Thu, Nov 12, 2015 at 10:06 PM, Thomas A Caswell <[email protected]

wrote:

I know it maybe annoying to users, but I am currently much more worried
about regressions (ie things we broke between 1.4.3 and 1.5.0) than
long standing bugs.


Reply to this email directly or view it on GitHub
#5474 (comment)
.

@tacaswell
Copy link
Member

This is wrapped up in the fact that we need a layout engine. There was a
prototype using a linear constraint solver a while ago, but the hard part
is going to be (automatically?) generating the constraints.

On Fri, Nov 13, 2015 at 9:33 AM Benjamin Root [email protected]
wrote:

This is going to be a tough one to solve. Technically speaking, there is no
bug here. tight_layout() is doing exactly what it is supposed to do. The
problem is that the xlabel text object has a position relative to the
x-axis, while the title has a position defined relative to the edge of the
subplot region. These two positions are only loosely related to each other,
and there is certainly no constraint system in place to enforce relative
positions from each other.

On Thu, Nov 12, 2015 at 10:06 PM, Thomas A Caswell <
[email protected]

wrote:

I know it maybe annoying to users, but I am currently much more worried
about regressions (ie things we broke between 1.4.3 and 1.5.0) than
long standing bugs.


Reply to this email directly or view it on GitHub
<
#5474 (comment)

.


Reply to this email directly or view it on GitHub
#5474 (comment)
.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 13, 2015

Re: "I suspect the problem here is that the title is attached to the first axes, but the axis label is attached to the twin."
Actually not, if you move the first axes' xlabel and xticks to top (gca().xaxis.set_{label,ticks}_position("top")) you suffer from the same problem.

@Tillsten
Copy link
Contributor

@tacaswell The hard are not the constraits, that mostly busy-work. The hard part
is including it in a backwards compatible way. Also there is still the same chicken-egg problem which
is also faced by tight_layout that some variables are only known after drawn (labelsizes, ticklabelsizes).

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@anntzer anntzer added the topic: geometry manager LayoutEngine, Constrained layout, Tight layout label Oct 20, 2017
@anntzer
Copy link
Contributor Author

anntzer commented Oct 20, 2017

@jklymak Sorry I ended up not having much time so far to look at your geometry manager PR, but perhaps this issue may be of interest for you...

@jklymak
Copy link
Member

jklymak commented Oct 21, 2017

I've not dared look at twinx/twiny yet, but if they are rationally constructed then this shouldn't be very hard.

@jklymak
Copy link
Member

jklymak commented Oct 21, 2017

OK, I got twinx/twiny to work, but it doesn't fix this problem because #9082 doesn't handle things below the axes level, and title placement etc is handled at a level below that.

I'll note that this problem is much more simple than this makes it seem, and has nothing to do with twiny other than twiny puts the xlabel at the top. And it has absolutely nothing to do w/ tight_layout.

import matplotlib.pyplot as plt
fig, ax = plt. subplots()
ax.xaxis.tick_top()
ax.xaxis.set_label_position('top')

ax.set_xlabel('Parent xlabel')
ax.set_title('Hello')

figure_1

@anntzer
Copy link
Contributor Author

anntzer commented Oct 21, 2017

Well, I actually did need labels both on top and on bottom (for separate axes).

@jklymak
Copy link
Member

jklymak commented Oct 21, 2017

Sure, its still an issue.

I'm just saying tight_layout and twiny are red-herrings; the real problem is that title doesn't care/know that there is an x-axis right there.

A geometry manager at the sub-axes level would be great too, and probably manageable for xlabel, ylabel, and title. Once we get into tick labels and ticks themselves things get hairy. And some seem to think layout managers would be good for placing legends, etc around data. That hurts my head. Not saying its not all possible, but just getting subplot placement sorted out was tough, and that should be the easy job...

@jklymak
Copy link
Member

jklymak commented Oct 21, 2017

Closing as a duplicate of #1415

@jklymak jklymak closed this as completed Oct 21, 2017
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
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

6 participants