Suppose you have a plot with multiple lines, e.g.,
plt.plot(np.arange(0, 10, 0.1), np.sin(np.arange(0, 10, 0.1)), label = 'sin')
plt.plot(np.arange(0, 10, 0.1), np.cos(np.arange(0, 10, 0.1)), label = 'cos')
plt.legend()
You will have a plot like
However, this may not work well if there are many plots. Is there an elegant way that we could move the legend to teh right of each line plot, with the corresponding color, e.g. the following?