Skip to content

y-axis label no longer obeys x position in 2.0 #7946

Closed as not planned
Closed as not planned

Description

@robroc

Using matplotlib with Seaborn's FacetGrid. Before upgrade to 2.0, setting the x,y position of the y-axis label worked. Now only y-position is respected.

import seaborn as sns
import matplotlib.pyplot as plt

g = (sns.FacetGrid(df, col="prenom", hue="sexe", col_wrap=3, size=3, sharey=False, legend_out=True)
 .map(plt.plot, "annee", "freq", ms=3, linewidth=3))

g.set(xlim=(1980, 2015), xticks=[1980, 1990, 2000, 2010], ylim=0)
g.set_titles('{col_name}')
g.fig.subplots_adjust(top = 0.91, wspace=0.3, hspace=0.3)
g.set_titles('{col_name}', size=13, fontweight='bold', ha='left')
g.set_axis_labels('', 'BABIES')

### This is the line that is not working ###
g.set_ylabels(rotation=0, position=(0, 1.04), color='grey')

g.fig.suptitle('Names that changed gender', x = 0.1, ha='left')
sns.plt.legend(loc='upper left',bbox_to_anchor=(1.5,1))
sns.despine()

It doesn't mater if I put 0 or 999999999 as the x value in the position parameter. The label is always in the same horizontal place.

Matplotlib version 2.0, Python 3.5 on Mac OSX El Capitan in Jupyter notebook
Matplotlib installed via conda update matplotlib

Activity

  1. WeatherGod commented on Jan 25, 2017

    @WeatherGod
    Member
  2. robroc commented on Jan 25, 2017

    @robroc
    Author

    You're right, my apologies. Here's an example in pure matplotlib. The x position is still ignored.

    roberto = noms[noms.prenom == 'roberto'.upper()]
    roberto = roberto.pivot_table('freq', index='annee', columns='sexe')
    
    fig, ax = plt.subplots()
    ax.title.set_text('Babies named Roberto')
    ax.plot(roberto)
    ax.axes.set_ylabel('BABIES', rotation=0, position=(2000,1.05))

    baaaaaaelftksuqmcc

  3. added this to the milestone on Jan 25, 2017
  4. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Jan 25, 2017
  5. NelleV commented on Jan 26, 2017

    @NelleV
    Member

    Here is the full code to reproduce the problem:

    import matplotlib.pyplot as plt
    import numpy as np
    
    roberto = np.random.randint(0, 100, size=(10, ))
    
    fig, ax = plt.subplots()
    ax.title.set_text('Babies named Roberto')
    ax.plot(roberto)
    ax.set_ylabel('BABIES', rotation=0, position=(2000,1.05))
  6. NelleV commented on Jan 26, 2017

    @NelleV
    Member

    I have the same results on matplotlib 1.5 and matplotlib 2.0.
    Which version of matplotlib are you using?

  7. removed
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Jan 26, 2017
  8. robroc commented on Jan 27, 2017

    @robroc
    Author
  9. dstansby commented on Feb 1, 2017

    @dstansby
    Member

    After a play around I've found that by setting position=(x,y), y is in figure co-ordinates, so y=0.5 puts the label halfway up the axis. Setting x=2000 (if it worked) would probably put the legend way off the the right of the figure.

    I can't seem to be getting it working in 1.5.3 either, do you know what version you upgraded from?

  10. robroc commented on Feb 1, 2017

    @robroc
    Author
  11. dstansby commented on Feb 1, 2017

    @dstansby
    Member

    Hmm, I'm not convinced setting x location of a y-label or y location of an x-label ever worked. The relevant line which sets the label location I think is https://github.com/matplotlib/matplotlib/blame/master/lib/matplotlib/axis.py#L2161 which hasn't changed for at least 5 years.

    It might be worth another dev having a look... In the meantime I'd recommend just adding a normal text box to the plot which should give you full control over position.

  12. modified the milestones: , on Mar 18, 2017
  13. dstansby commented on Mar 18, 2017

    @dstansby
    Member

    Punting this to 2.1 as no-one has disagreed (yet) with my assertion that this never worked.

  14. dstansby commented on Mar 19, 2017

    @dstansby
    Member

    After a bit of a hunt, I think this is a duplicate of #7112

  15. 19 remaining items

  16. fperonaci commented on Oct 16, 2020

    @fperonaci

    I understand, thanks for the explanation.

    Well, it's because tick labels have different width, e.g. the label for the value -1 is very large compared to, say, the labels for 1,2,3, etc. In my case I only have one label with the minus sign which is pretty far from the axis label. So it is OK to have the label nominally overlapping the tick labels, since in practice it does not (they are physically far apart). Actually, it looks better to have it closer to the axis.

    For what concerns me, now I have understood how this works, and that is fine.
    However, maybe it is good to get rid of some inconsistencies on the long run.

    So for example, compare:

    ax = plt.gca()
    ax.xaxis.set_label_text('x-label')
    ax.xaxis.set_label_coords(0.5,0.5)
    

    with

    ax = plt.gca()
    ax.set_xlabel('x-label',position=(0.5,0.5))
    

    It seems reasonable that the two snippets should do the same, but they do not.

  17. jklymak commented on Oct 16, 2020

    @jklymak
    Member

    Sure, I agree - thats the suggested fix, is for someone to make the automatic label repositioning over-rideable with manual values if desired, like we did in #17127 for the title.

  18. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  19. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  20. modified the milestones: v3.6.0, v3.7.0 on Aug 24, 2022
  21. github-actions commented on Jan 26, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  22. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Feb 26, 2024
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

    New featurestatus: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: ticks axis labels🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions