Skip to content

Commit 2b9c228

Browse files
committed
Merge pull request #4193 from tacaswell/fix_color_rc
BUG/API : fix color validation
2 parents dba7626 + f034cde commit 2b9c228

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/matplotlib/legend.py

+10
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ def __init__(self, parent, handles, labels,
345345
# We use FancyBboxPatch to draw a legend frame. The location
346346
# and size of the box will be updated during the drawing time.
347347

348+
if rcParams["legend.facecolor"] == 'inherit':
349+
facecolor = rcParams["axes.facecolor"]
350+
else:
351+
facecolor = rcParams["legend.facecolor"]
352+
353+
if rcParams["legend.edgecolor"] == 'inherit':
354+
edgecolor = rcParams["axes.edgecolor"]
355+
else:
356+
edgecolor = rcParams["legend.edgecolor"]
357+
348358
self.legendPatch = FancyBboxPatch(
349359
xy=(0.0, 0.0), width=1., height=1.,
350360
facecolor=rcParams["axes.facecolor"],

lib/matplotlib/rcsetup.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ def __call__(self, s):
244244
raise ValueError('Could not convert all entries to ints')
245245

246246

247+
def validate_color_or_inherit(s):
248+
'return a valid color arg'
249+
if s == 'inherit':
250+
return s
251+
return validate_color(s)
252+
253+
247254
def validate_color(s):
248255
'return a valid color arg'
249256
try:
@@ -254,6 +261,7 @@ def validate_color(s):
254261
if is_color_like(s):
255262
return s
256263
stmp = '#' + s
264+
257265
if is_color_like(stmp):
258266
return stmp
259267
# If it is still valid, it must be a tuple.
@@ -606,7 +614,7 @@ def __call__(self, s):
606614
'image.lut': [256, validate_int], # lookup table
607615
'image.origin': ['upper', six.text_type], # lookup table
608616
'image.resample': [False, validate_bool],
609-
# Specify whether vector graphics backends will combine all images on a
617+
# Specify whether vector graphics backends will combine all images on a
610618
# set of axes into a single composite image
611619
'image.composite_image': [True, validate_bool],
612620

@@ -696,6 +704,8 @@ def __call__(self, s):
696704
# the relative size of legend markers vs. original
697705
'legend.markerscale': [1.0, validate_float],
698706
'legend.shadow': [False, validate_bool],
707+
'legend.facecolor': ['inherit', validate_color_or_inherit],
708+
'legend.edgecolor': ['inherit', validate_color_or_inherit],
699709

700710
## tick properties
701711
'xtick.major.size': [4, validate_float], # major xtick size in points

0 commit comments

Comments
 (0)