How to change the legend edgecolor and facecolor in matplotlib

Solution 1:

You can set the edge color and the face color separately like this:

frame.set_facecolor('green')
frame.set_edgecolor('red')

There's more information under FancyBboxPatch here.

Solution 2:

Using matplotlib.pyplot, plt.legend(facecolor='white', framealpha=1) will give your legend a white background without transparency.

Solution 3:

In addition to Molly's method you can turn the frame off using the linewidth:

frame.set_linewidth(0)

I used that method in a small convenience function I wrote to hide the legend frames for the same reason you cite. The function is called adjust_legends in the print_targeted_plots module available from github.