import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
ax = plt.axes()
plot = []
plot += ax.plot(x, y1, label='sin(x)')
plot += ax.plot(x, y2, label='cos(x)')
plot += ax.plot(x, y1 * 2, label='sin(x)')
plot += ax.plot(x, y2 * 4, label='cos(x)')
plt.xlabel('X')
plt.ylabel('Y')
legend=['1', '2', '3', '4']
ax.legend(plot, legend, ncol=2)
plt.show()
How to change the order of legend output without changing arrays plot and legend?
The order should be as in the picture
Read the documentation. It is possible to do without handles?