In matplotlib, how do I specify the line width and color of a legend frame?
Import the various modules and libraries you need for the plot: matplot library matplot , numpy , pyplot . Create your data set(s) to be plotted. In the plot() method after declaring the linewidth parameter, you assign it to any number value you want to represent the desired width of your plot.
The prop keyword is used to change the font size property. It is used in Matplotlib as Using a prop keyword for changing the font size in legend.
Matplotlib allows you to adjust the line width of a graph plot using the linewidth attribute. If you want to make the line width of a graph plot thinner, then you can make linewidth less than 1, such as 0.5 or 0.25.
You can use the keyword argument linewidth or the shorter lw to change the width of the line.
For the width: legend.get_frame().set_linewidth(w)
For the color: legend.get_frame().set_edgecolor("red")
Got the answer:
legend = axes.legend()
frame = legend.get_frame()
and then we can use frame.set_XXX
to specify the properties of the frame.
Didn't find it at first because it's not an input argument of the plt.legend()
method.
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