Skip to content

Legend handles and lables are not available via ax.get_legend_handles_labels() #293

@Zerosimi

Description

@Zerosimi

Hi everyone,

I'm plotting multiple windrose axes and I want to have a common legend for them. While working on that, I found that the legend handles and labels are unavailable via the ax.get_legend_handles_labels() routine. Would be nice if that functionality could be there. Below you find a minimal working example that shows the issue: The legend will be empty using ax.get_legend_handles_labels(), even though with the ax.set_legend() method, a legend with handles and labels appears.

Minimal working example

# Dummy data
ws = np.linspace(0, 10, 20)
wd = np.linspace(0, 360, 20)

# Plotting
fig = plt.figure()
ax = windrose.WindroseAxes.from_ax(fig=fig)

# Windrose plot
ax.bar(
    wd,
    ws,
    bins=np.linspace(0, 9, 4),
)

# Legend
# ax.set_legend() # This would work as expected
h, l = ax.get_legend_handles_labels()  # Returns ([ ],[ ])
fig.legend(ncols=len(h), loc="lower center", labels=l, handles=h)

plt.show()
plt.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions