-1

Here is the code snippet I'm using to plot the graph:

plt.figure(figsize=(15,6))
plt.xticks(rotation='vertical')
for frame in top20s:
    plt.plot(frame['name'][:20], frame['pb'][:20], label=frame.league)
plt.legend()
plt.show()

And below is what I get: enter image description here

How would I remove all the duplicates in the legend, and have one for each plots?

Joseph Seung Jae Dollar
  • 1,016
  • 4
  • 13
  • 28
  • 2
    It's hard to say without knowing the structure of your data, Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Please provide mockup data, in particular check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Diziet Asahi Mar 08 '18 at 08:28

1 Answers1

0

The problem is that you are labeling your lines with an entire dataframe column. Instead you would want to only use one of the column's entries as label.

I.e. instead of plt.plot(..., label=frame.league) use

plt.plot(..., label=frame.league[0])

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712