Legend¶
AX.legend(
loc="lower center",
bbox_to_anchor=(1.0, 1.03),
ncol=N_COLS,
handletextpad=0.2,
borderaxespad=0.2,
columnspacing=1.0,
labelspacing=0.2,
)
AX.get_legend().set_title(None)
Horizontal List¶
By default, labels in a legend are listed vertically. This does not have an explicit effect when there is only one legend column (the default case). However, when manually setting the number of legend columns greater than one (e.g., by AX.legend(ncol=2)), the result is not as expected if the legend is put on top/bottom of the subplots (which is commonly used in research paper figures).
To make the legend labels list horizontally, we first define a utility function that reshapes the label matrix:
def flip_legend_labels(items, ncol: int):
return itertools.chain(*[items[i::ncol] for i in range(ncol)])
Then, we can redraw the legend after it is generated by Seaborn: