Skip to content

Figure legend not keeping Line2D marker #9155

Closed
@anhiga

Description

@anhiga

Bug report

Bug summary

When retrieving handles used in legend, marker property is not kept.

Code for reproduction

import matplotlib.pyplot as plt

point = plt.Line2D([1],[1], marker='o')
legend = plt.gcf().legend(handles=[point], labels=['point'])

# First way
handles = legend.legendHandles
handles[0].get_marker()
# Second way
lines= legend.get_lines()
lines[0].get_marker()

Actual outcome

Out[1]: ''

Expected outcome
When plotting an Axes legend, get_legend_handles_labels() can be used, which does return the right marker. There isn't such a method in Figure, so when using Legend methods or properties such as legend.get_lines() or legend.legendHandles, line2D marker isn't kept.

Is there a better way of retrieving handles from a legend?
Am I doing something wrong?

Matplotlib version

  • Operating System: Windows 10
  • Matplotlib Version: 2.0.2
  • Python Version: 3.6.1

cc @juanlu001

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions