0

I have a graph with multiple lines which creates a legend that is fairly large. I would like to instead have the values that are shown in the legend to appear next to the lines itself on the right side of the chart. Could someone help me with the code that would allow me to do this? The code I currently have is shown below and so is a picture of what it creates. Thanks in advance!

plt.style.use('fivethirtyeight')
fig, ax = plt.subplots()
fig.set_size_inches(12, 6)
b_PTS_F.plot(ax=ax)
ax.set_title("2012 PPG by Forwards", fontsize=20, loc='center')
ax.set_ylabel('Points per Game')
ax.legend(loc='lower left', fontsize='10')
plt.axvline(2.5,ls='--')`

NBA Forwards chart

  • Possible duplicate of [How to put the legend out of the plot](http://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot) – some_weired_user May 09 '16 at 21:18

1 Answers1

0

I don't have your data, so had to make up some random numbers.

a = np.random.randn(100).reshape(10,10)*10
names = list('abcdefghij')
colors = plt.cm.viridis(np.linspace(0, 1, 10))
for i, y in enumerate(a):
    plt.plot(y, c=colors[i])
    plt.text(9, y[-1], names[i], color=colors[i], verticalalignment='center', horizontalalignment='left')
plt.xlim(0, 9.5)
plt.show()

enter image description here

Phlya
  • 5,726
  • 4
  • 35
  • 54