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
?
Set the figure size and adjust the padding between and around the subplots. Using plot() method, plot lines with the labels line1, line2 and line3. Place a legend on the figure using legend() method, with number of labels for ncol value in the argument.
We can change the line width (line thickness) of lines in Python Matplotlib legend by using the set_linewidth() method of the legend object and the setp() method of the artist objects.
import textwrap [...] renames = {c: textwrap. fill(c, 15) for c in df. columns} df. rename(renames, inplace=True) [...]
To change the position of a legend in Matplotlib, you can use the plt. legend() function. The default location is “best” – which is where Matplotlib automatically finds a location for the legend based on where it avoids covering any data points.
When you create your legend add the handlelength
keyword (doc) which sets the length of the '---' (which is called the handle).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With