Hi everybody, I'm new to this list, so please don't be too
> impatient...
> I would like to know which possibilities I have to
> customize the legend. I already found how to change the
> font size using font_manager and FontProperties. What I'd
> like to have is a slight gray legend background. Is this
> possible?
Hi Sascha,
The way to customize the legend is to get the legend instance back
from the legend command. Then you can call any of the methods
available for the legend. You can read about these by doing from the
python shell
>>> leg = legend(blha, blah)
>>> help(leg)
or reading the site documentation at
http://matplotlib.sourceforge.net/matplotlib.legend.html#Legend . To
customize the rectangular box around the legend, use
>>> rect = leg.get_frame()
rect is a Rectangle instance, documented at
http://matplotlib.sourceforge.net/matplotlib.patches.html#Rectangle .
To change the facecolor to gray, you need to call
>>> rect.set_facecolor(0.8) # a grayscale intensity
or
>>> rect.set_facecolor('gray')
There are many wanys to set colors in matplotlib, these are discussed
at http://matplotlib.sourceforge.net/matplotlib.pylab.html#-colors
In particular, see examples/legend_demo.py that comes with the
matplotlib source distribution (and is also available here
http://matplotlib.sourceforge.net/matplotlib_examples_0.74.zip ).
This example shows you how to set the background color and more.
Hope this helps,
JDH