Dear Matplotlib developers,
Attached is a patch to improve the functionality of legend.
The two biggest changes are as follows,
* Drawing of legend is delegated to "legend handlers".
* Introduces a new "Container" class. This is primarily to support
legend of complex plots (e.g., bar, errorbar, etc).
The first change is to ease the creation of customized legends. See
"legend_demo_custom_handler.py" for example.
The second change is to support legend of complex plots. Axes
instances now have a "containers" attribute. And this is only intended
to be used for generating a legend. For example, "bar" plots create a
series of Rectangle patches. Previously, it returned a list of these
patches. With the current change, it creates a container object of
these rectangle patches and return it instead. As the container class
is derived from a tuple, it should be backward-compatible.
Furthermore, the container object is added to the Axes.containers
attributes. And legend command use this "container" attribute to
properly create a legend for the bar.
A two example figures are attached.
As this patch introduces relatively significant changes. I wanted to
get some comments from others before I commit.
The change will be divided into four commits.
legend_refactor.patch (38.7 KB)