8000 Let legend get the handles from the provided objects if not specified explicitly. · Issue #16567 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Let legend get the handles from the provided objects if not specified explicitly. #16567
Closed
@Wrzlprmft

Description

@Wrzlprmft

Consider the following example:

import matplotlib.pyplot as plt
import numpy as np

fig,axes = plt.subplots()
line_A = axes.plot( np.random.random(10), label="foo" )[0]
line_B = axes.plot( np.random.random(10), label="bar" )[0]
line_C = axes.plot( np.random.random(10), label="quz" )[0]
lines = [line_A,line_B]

axes.legend( lines, [line.get_label() for line in lines] )

The last line needs to be this complicated since I get unwanted internal information if I just use axes.legend(lines). However, this seems like something legend could do automatically: If I do not specify the handles for the legend, it extracts them from whatever I give it automatically.

This may be a duplicate of this request, but I am not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0