Skip to content

tight_layout puts axes title below twiny xlabel  #5474

Closed

Description

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

tight_twiny
matplotlib 1.5.0.

Activity

  1. tacaswell commented on Nov 13, 2015

    @tacaswell
    Member

    Is this a regression from 1.4.3?

  2. added this to the milestone on Nov 13, 2015
  3. tacaswell commented on Nov 13, 2015

    @tacaswell
    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.

  4. anntzer commented on Nov 13, 2015

    @anntzer
    ContributorAuthor

    1.4.3 suffers from the same issue.

  5. tacaswell commented on Nov 13, 2015

    @tacaswell
    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.

  6. WeatherGod commented on Nov 13, 2015

    @WeatherGod
    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 <notifications@github.com

    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)
    .

  7. tacaswell commented on Nov 13, 2015

    @tacaswell
    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 notifications@github.com
    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 <
    notifications@github.com

    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)
    .

  8. anntzer commented on Nov 13, 2015

    @anntzer
    ContributorAuthor

    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.

  9. Tillsten commented on Nov 17, 2015

    @Tillsten
    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).

  10. modified the milestones: , on Oct 3, 2017
  11. anntzer commented on Oct 20, 2017

    @anntzer
    ContributorAuthor

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

  12. jklymak commented on Oct 21, 2017

    @jklymak
    Member

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

  13. jklymak commented on Oct 21, 2017

    @jklymak
    Member

    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

  14. anntzer commented on Oct 21, 2017

    @anntzer
    ContributorAuthor

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

  15. jklymak commented on Oct 21, 2017

    @jklymak
    Member

    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...

  16. jklymak commented on Oct 21, 2017

    @jklymak
    Member

    Closing as a duplicate of #1415

  17. modified the milestones: , v2.2.0 on Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: geometry managerLayoutEngine, Constrained layout, Tight layout

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions