1

I want to reproduce this label out of a picture and a line (see: Replace Matplotlib legend's labels with image), but when I try to move it outside the axis with bbox_to_anchor the line in the label vanishes, while the picture remains. Nothing gets cut off. Below is the relevant code-part. As I have more than one line, I use lists of lines and lists of legends (the latter is empty).

plt.legend(handles = lineliste, labels = legendliste, handler_map = 
handler_map, handlelength=4, labelspacing=0.0, fontsize=36, borderpad=0.1, 
handletextpad=0.2, borderaxespad=0.1, handleheight=2, loc="upper center", 
frameon = False, bbox_to_anchor=(2.02,1))

@ImportanceOfBeingErnest Do you have a solution, as you offered the answer to the first question?

Alon
  • 687
  • 1
  • 6
  • 10
Mary
  • 23
  • 5

1 Answers1

0

Sorry, in the original solution there was a

l.set_clip_on(False) 

missing. I edited that answer. It'll now look like

enter image description here

when bbox_to_anchor=(1.1,1) is added to the legend call.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Thank you! is there a way to adjust the position of the handlers inside the box? right now the distance at the bottom is larger than the one on top. In my case, with more entries, this results in some entries not being inside the box – Mary Nov 04 '18 at 18:01
  • I'm sure that's possible; but I have no idea what the problem is. See [mcve]. – ImportanceOfBeingErnest Nov 04 '18 at 18:16
  • I posted a new question (https://stackoverflow.com/questions/53145003/how-can-the-position-of-a-legend-handler-in-the-legend-box-be-adjusted-in-matplo) following the advice given. I would appreciate your help! – Mary Nov 04 '18 at 20:15