0

I have been trying to change the order of the legend on a plot in Pandas to get it in the same order as the plot appears:

Screenshot of the code and the plot in Anaconda

As you see, the plots are stacking by increasing the amount of %K and I would like the legend to be reversed so the plot can be easier to read.

How can I do this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

You can call this before the loop:

 fig, ax = plt.subplots()

And then before plotting:

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[::-1], labels[::-1])

As it's stated here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Piotr Nowakowski
  • 376
  • 1
  • 11