31

Lets say i'm plotting a line with matplotlib and add a legend. Within the legend it says ------ Label. I find the default horizontal length of this line a bit too long when plotting small figure sizes for print.

Is there a property to set ------ Label to --- Label?

bioslime
  • 1,821
  • 6
  • 21
  • 27

1 Answers1

52

When you create your legend add the handlelength keyword (doc) which sets the length of the '---' (which is called the handle).

tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • 11
    To complete: this typically comes as `plt.legend(handlelength=4)` if you want to increase from the default (2) to another value. This comes handy if the marker conflicts with the linestyle, making it unreadable. – François Landes Apr 13 '20 at 17:50