Specifying the line width of the legend frame, in matplotlib

In matplotlib, how to specify the line width and border color of a legend?

+8
python matplotlib
source share
2 answers

For width: legend.get_frame().set_linewidth(w)

For color: legend.get_frame().set_edgecolor("red")

+11
source share

Got a response:

 legend = axes.legend() frame = legend.get_frame() 

and then we can use frame.set_XXX to specify the properties of the frame.

I did not find it at first, because this is not an input argument to the plt.legend() method.

+3
source share

All Articles