By default Matplotlib orders the entries in the legend by column, e.g.,
In [48]: from matplotlib.pyplot import subplots, show
...: f, ax = subplots(figsize=(6, 2), constrained_layout=True)
...: for i in range(1, 10):
...: ax.plot((0,1),(0,1), label=str(i))
...: ax.legend(ncol=4, loc=3)
...: show()
but I'd like better to have the entries listed by rows, like
1 2 3 4
5 6 7 8
9
I could reorder the handles and labels and invoke ax.legend
passing the reordered lists (I'll post that as an answer if requested in comments) but I'd like to know if there is a more direct and straightforward way to instruct Matplotlib to do as I want, so that I don't have to copy and paste the reorder solution in 50% of the Matplotlib scripts I'll write…