Skip to content

Axes doesn't have legends attribute? #8187

Closed

Description

@katzenbaer

In the Artist tutorial, it says that Axes have a legends attribute that is "A list of Legend instances". However, my Axes don't seem to have this attribute using matplotlib v2.0.

Is the tutorial wrong or is there a regression in matplotlib?

screen shot 2017-03-02 at 3 12 24 pm

screen shot 2017-03-02 at 3 06 23 pm

Activity

  1. tacaswell commented on Mar 2, 2017

    @tacaswell
    Member

    I think the tutorial has been wrong for a very long time (Figure objects do have legends attribute though).

    As near as I can tell Axes never had an legends attribute and the legends guide even explains a work around to the hard-coded 1:1 mapping of legend to axes (http://matplotlib.org/users/legend_guide.html#multiple-legends-on-the-same-axes).

    That particular line goes back to 2008 (f0f28a3).

    Checking out that commit and searching for legends gives:

    ✔ ~/source/p/matplotlib [:f0f28a3ef|⚑ 8] 
    18:41 $ git grep legends
    CHANGELOG:2005-10-26 Added support for scatter legends - thanks John Gill
    doc/users_guide/artist_api_tut.txt:legends               A list of Figure Legend instances (different from Axes.legends)
    doc/users_guide/artist_api_tut.txt:ax.legend - axes legends         Legend                ax.legends
    doc/users_guide/artist_api_tut.txt:legends           A list of Legend instances
    docs/users/artists.rst:legends               A list of Figure Legend instances (different from Axes.legends)
    docs/users/artists.rst:ax.legend - axes legends         Legend                ax.legends
    docs/users/artists.rst:legends           A list of Legend instances
    examples/pylab/legend_auto.py:algorithm, but shows lots of different ways to create legends so is
    lib/matplotlib/axes.py:        legends), linewidth, anitialising, marker face color, etc.  Here is an
    lib/matplotlib/backends/backend_emf.py:        # legends where the circles are small anyway, and it is
    lib/matplotlib/figure.py:        children.extend(self.legends)
    lib/matplotlib/figure.py:        self.legends = []
    lib/matplotlib/figure.py:        for legend in self.legends:
    lib/matplotlib/figure.py:          'best' : 0,          (currently not supported for figure legends)
    lib/matplotlib/figure.py:        self.legends.append(l)
    lib/matplotlib/legend.py:  'best'         : 0, (only implemented for axis legends)
    lib/matplotlib/legend.py:      'best'         : 0, (only implemented for axis legends)
    lib/matplotlib/legend.py:    codes = {'best'         : 0, # only implemented for axis legends
    
    
  2. added this to the milestone on Mar 2, 2017
  3. katzenbaer commented on Mar 3, 2017

    @katzenbaer
    ContributorAuthor

    Then assuming I am in the one-legend-per-Axes scenario, is accessing the Axes's legend via the legend_ instance variable the officially supported (and more importantly – safe) method?

  4. tacaswell commented on Mar 3, 2017

    @tacaswell
    Member

    There is a get_legend() method that is what should probably be used. Not sure what the trailing _ means here...

  5. katzenbaer commented on Mar 3, 2017

    @katzenbaer
    ContributorAuthor

    Oh, didn't realize there was a get_legend() method. I think the trailing _ is to avoid conflict with the legend() method, although it's an interesting choice to have it as legend_ instead of _legend.

  6. modified the milestones: , on May 3, 2017
  7. modified the milestones: , on Oct 9, 2017
  8. modified the milestones: needs sorting, v3.6.0 on Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions