PatchCollection legends now supported#
PatchCollection instances now properly display in legends when given a label.
Previously, labels on PatchCollection objects were ignored by the legend
system, requiring users to create manual legend entries.
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.collections import PatchCollection
fig, ax = plt.subplots()
patches = [mpatches.Circle((0, 0), 0.1), mpatches.Rectangle((0.5, 0.5), 0.2, 0.3)]
pc = PatchCollection(patches, facecolor='blue', edgecolor='black', label='My patches')
ax.add_collection(pc)
ax.legend() # Now displays the label "My patches"
plt.show()
(Source code, 2x.png, png)
This fix resolves #23998.