1

By default when I call matplotlib legend the output is:

default legend matplotlib

But in my case, I want the text to have the color of the line and I want to remove the line of the legend.

Desired outcome:

enter image description here

How can I do this?

Partial sucess

My searches only allowed me to get the text with the correct colors

enter image description here

and puting those lines transparent

enter image description here

But there is still space on the legend box.

Is there a way to make this?

gota
  • 2,338
  • 4
  • 25
  • 45

1 Answers1

3

I ended up finding the answer:

When you call the legend add these properties

ax.legend(handlelength=0, handletextpad=0)

Those lines are called handles, and you set their length to 0 and with no pad between them and the text.

gota
  • 2,338
  • 4
  • 25
  • 45
  • That works visually, but actually there is still an object there and some renders display the object – gota Jan 27 '20 at 16:05