0
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 enter image description here

Read the documentation. It is possible to do without handles?

ShaiMar
  • 13
  • 4
  • 1
    Without handles - I'm afraid not; with handles - see https://stackoverflow.com/questions/10101141/matplotlib-legend-add-items-across-columns-instead-of-down – Andrey Sobolev Apr 20 '23 at 08:37

0 Answers0