user1850133 user1850133 - 1 year ago 747
Python Question

matplotlib legend background color

Is there while

rcParams['legend.frameon'] = 'False'
a simple way to fill the legend area background with a given colour. More specifically I would like the grid not to be seen on the legend area because it disturbs the text reading.

The keyword
sounds like what I need but it doesn't change anything.

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['legend.frameon'] = 'False'
plt.plot(range(5), label = u"line")
plt.legend(loc = best)

I've also tried:

legend = plt.legend(frameon = 1)
frame = legend.get_frame()

but then I need to ask how can I change the background colour while keeping the frame on? Sometimes I want it ON with a background colour other than white. And also, is there a way of changing the colour of the frame? With the above code I was expecting to change the colour of the frame only, not the background.

Answer Source

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


There's more information under FancyBboxPatch here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download