Allow multiple legends
A long-requested feature (see e.g. #32) (probably the second most asked-for feature, after built-in webmaps) is the ability to have multiple legends on a single plot. E.g. if a plot uses both hue and scale visual variables, it makes sense to have both a hue and a scale legend. However, currently only a single legend for one or the other is allowed—not both.
matplotlib allows creating multiple legends on the same axis, with some reservations. Some trickiness that comes up when considering implementing this feature:
-
What to do if one legend is a colorbar legend and the other a regular legend?
-
What happens if we add a third visual variable to the plot in the future? How would our handing of legends adapt?
-
How would this interact with the
legendandlegend_varparameters? -
It appears that legend positions cannot be inferred automatically more than once:
Sometimes it is more clear to split legend entries across multiple legends. Whilst the instinctive approach to doing this might be to call the legend() function multiple times, you will find that only one legend ever exists on the Axes. This has been done so that it is possible to call legend() repeatedly to update the legend to the latest handles on the Axes, so to persist old legend instances, we must add them manually to the Axes: