I was wondering how I can produce such fancy legends in matplotlib
. In particular, I'd like to know how to group, for example, both solid and dashed blue lines which correspond to $\tau=10$ side by side, or all dashed (or solid) lines together as in the lower part of the legend.
Take-home messages
The legend docs specifies a more natural way to group the entries using
HandlerTuple
(example here). But sincempl
places the markers horizontally, such an approach is orthogonal to what I wished :). If it doesn't bother you, go for that option first.As far as I understood, custom legends are designed such that they don't exchange any information with the data you want to plots. For example, in my case, I cannot tell the
AnyObjectHandler
how many lines are going to be grouped, what are theirlinestyle
, etc. It is a good decision for generality, with the expense of a (minimal) harm to the code refactoring.