Skip to content

Commit df2cc62

Browse files
committed
STY: make default legend edgecolor gray; add kwargs for edgecolor, facecolor
1 parent d42e3e9 commit df2cc62

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

lib/matplotlib/legend.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def __init__(self, parent, handles, labels,
180180
title=None, # set a title for the legend
181181

182182
framealpha=None, # set frame alpha
183+
edgecolor=None, # frame patch edgecolor
184+
facecolor=None, # frame patch facecolor
183185

184186
bbox_to_anchor=None, # bbox that the legend will be anchored.
185187
bbox_transform=None, # transform for the bbox
@@ -197,21 +199,20 @@ def __init__(self, parent, handles, labels,
197199
================ ====================================================
198200
Keyword Description
199201
================ ====================================================
200-
loc a location code
202+
loc Location code string, or tuple (see below).
201203
prop the font property
202204
fontsize the font size (used only if prop is not specified)
203205
markerscale the relative size of legend markers vs. original
204-
markerfirst If true, place legend marker to left of label
205-
If false, place legend marker to right of label
206+
markerfirst If True (default), marker is to left of the label.
206207
numpoints the number of points in the legend for line
207208
scatterpoints the number of points in the legend for scatter plot
208209
scatteryoffsets a list of yoffsets for scatter symbols in legend
209-
frameon if True, draw a frame around the legend.
210-
If None, use rc
211-
fancybox if True, draw a frame with a round fancybox.
212-
If None, use rc
213-
shadow if True, draw a shadow behind legend
214-
framealpha If not None, alpha channel for the frame.
210+
frameon If True, draw the legend on a patch (frame).
211+
fancybox If True, draw the frame with a round fancybox.
212+
shadow If True, draw a shadow behind legend.
213+
framealpha Transparency of the frame.
214+
edgecolor Frame edgecolor.
215+
facecolor Frame facecolor.
215216
ncol number of columns
216217
borderpad the fractional whitespace inside the legend border
217218
labelspacing the vertical space between the legend entries
@@ -345,15 +346,15 @@ def __init__(self, parent, handles, labels,
345346
# We use FancyBboxPatch to draw a legend frame. The location
346347
# and size of the box will be updated during the drawing time.
347348

348-
if rcParams["legend.facecolor"] == 'inherit':
349-
facecolor = rcParams["axes.facecolor"]
350-
else:
349+
if facecolor is None:
351350
facecolor = rcParams["legend.facecolor"]
351+
if facecolor == 'inherit':
352+
facecolor = rcParams["axes.facecolor"]
352353

353-
if rcParams["legend.edgecolor"] == 'inherit':
354-
edgecolor = rcParams["axes.edgecolor"]
355-
else:
354+
if edgcolor is None:
356355
edgecolor = rcParams["legend.edgecolor"]
356+
if edgecolor == 'inherit':
357+
edgecolor = rcParams["axes.edgecolor"]
357358

358359
self.legendPatch = FancyBboxPatch(
359360
xy=(0.0, 0.0), width=1., height=1.,

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ def validate_hist_bins(s):
11461146
'legend.markerscale': [1.0, validate_float],
11471147
'legend.shadow': [False, validate_bool],
11481148
'legend.facecolor': ['inherit', validate_color_or_inherit],
1149-
'legend.edgecolor': ['none', validate_color_or_inherit],
1149+
'legend.edgecolor': ['0.8', validate_color_or_inherit],
11501150

11511151
# tick properties
11521152
'xtick.top': [False, validate_bool], # draw ticks on the top side

matplotlibrc.template

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ backend : $TEMPLATE_BACKEND
396396

397397
### Legend
398398
#legend.loc : best
399-
#legend.frameon : True # whether or not to draw a frame around legend
400-
#legend.framealpha : 0.8 # legend frame transparency
399+
#legend.frameon : True # if True, draw the legend on a background patch
400+
#legend.framealpha : 0.8 # legend patch transparency
401401
#legend.facecolor : inherit # inherit from axes.facecolor; or color spec
402-
#legend.edgecolor : none
402+
#legend.edgecolor : 0.8 # background patch boundary color
403403
#legend.fancybox : True # if True, use a rounded box for the
404-
# legend, else a rectangle
405-
#legend.shadow : False
404+
# legend background, else a rectangle
405+
#legend.shadow : False # if True, give background a shadow effect
406406
#legend.numpoints : 1 # the number of marker points in the legend line
407407
#legend.scatterpoints : 1 # number of scatter points
408408
#legend.markerscale : 1.0 # the relative size of legend markers vs. original

0 commit comments

Comments
 (0)