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

Skip to content

proposed ENH: object returned from compound Artist has legend attribute  #8389

@efiring

Description

@efiring

Specifying Artists in the desired order for a legend requires isolating the Artists from whatever is returned by a given plotting function. (#8283) It would be easier if the returned object could be passed directly. This could be done if the returned object gained a legend attribute encapsulating the handles and corresponding labels.

For example, plot returns a list. Instead, it could return a minimal list subclass with a legend attribute pointing to a minimal class which might have legend.artists and legend.labels tuples. Then the legend function would look at each entry in its list of "handles", and if the entry contains a legend attribute, it would use it's tuples, appending their info to its own lists; otherwise, it would use the handle directly, as it does at present.

A more complex case is the infamous hist, returning a tuple with contents that differ depending on how the function was called. Instead, it could return a minimal subclass of tuple with a legend attribute as described above.

I think this approach could be implemented while maintaining backwards compatibility, and that it also provides a framework for improving the API in other ways. For example, the object returned by hist could additionally be extended (subclass of namedtuple?) to allow access to its contents via names in addition to via indexing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions