0
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(12, 5))
axes.plot(error_list1, label = 'm =0', color='blue')
axes.plot(error_list2, label = '1e-1', color='red')
axes.plot(error_list3, label = '1e-3', color='green')
axes.plot(error_list4, label = '1e-4', color='yellow')
axes.grid()
axes.set_yscale('log')
axes.set(xlabel="iters", ylabel="Log loss function")
axes.legend()
axes.title.set_text('Loss func over different iterations')

The snippet above is adding multiple legend entries to myplot. What could be wrong?

enter image description here

  • Can you show what does that error lists you are supplying consists of. That is the one which is causing issue. Each error list might have had more than one list or array if it is an array or list. which is making it to plot 5 times and hence you are getting legend multiple times for each plot – Yagami_Light Mar 05 '22 at 03:47
  • [array([0.5, 0.5, 0.5, 0.5, 0.5]), array([0.25, 0.25, 0.25, 0.25, 0.25]), array([0.125, 0.125 – Adam Rainah Mar 05 '22 at 04:02
  • You are right, seems like each list element is a list itself. How do I keep only one value and discard others. All the values are same. – Adam Rainah Mar 05 '22 at 04:03
  • You can use list comprehension to make it a list of single value. [x.min() for x in error_list1] since all the values in the array are equal. there wont be any difference if you use min or max or mean or median. I hope this will solve your problem – Yagami_Light Mar 05 '22 at 04:30

0 Answers0