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()