Order your matplotlib legend

Sometimes you need a specific order of your labels in your matplotlib legend.You automatically will have an order of line1, line2, line3, scatter1, scatter2: But let’s say you need an order of scatter1, line1, scatter 2, .. The following snipped is an easy fix and very useful: handles, labels = ax.get_legend_handles_labels() order = [3,0,4,1,2] plt.legend([handles[idx]ContinueContinue reading “Order your matplotlib legend”