Skip to content

Commit

Permalink
Merge pull request #4193 from tacaswell/fix_color_rc
Browse files Browse the repository at this point in the history
BUG/API : fix color validation
  • Loading branch information
WeatherGod committed Apr 20, 2015
2 parents dba7626 + f034cde commit 2b9c228
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/matplotlib/legend.py
Expand Up @@ -345,6 +345,16 @@ def __init__(self, parent, handles, labels,
# We use FancyBboxPatch to draw a legend frame. The location
# and size of the box will be updated during the drawing time.

if rcParams["legend.facecolor"] == 'inherit':
facecolor = rcParams["axes.facecolor"]
else:
facecolor = rcParams["legend.facecolor"]

if rcParams["legend.edgecolor"] == 'inherit':
edgecolor = rcParams["axes.edgecolor"]
else:
edgecolor = rcParams["legend.edgecolor"]

self.legendPatch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor=rcParams["axes.facecolor"],
Expand Down
12 changes: 11 additions & 1 deletion lib/matplotlib/rcsetup.py
Expand Up @@ -244,6 +244,13 @@ def __call__(self, s):
raise ValueError('Could not convert all entries to ints')


def validate_color_or_inherit(s):
'return a valid color arg'
if s == 'inherit':
return s
return validate_color(s)


def validate_color(s):
'return a valid color arg'
try:
Expand All @@ -254,6 +261,7 @@ def validate_color(s):
if is_color_like(s):
return s
stmp = '#' + s

if is_color_like(stmp):
return stmp
# If it is still valid, it must be a tuple.
Expand Down Expand Up @@ -606,7 +614,7 @@ def __call__(self, s):
'image.lut': [256, validate_int], # lookup table
'image.origin': ['upper', six.text_type], # lookup table
'image.resample': [False, validate_bool],
# Specify whether vector graphics backends will combine all images on a
# Specify whether vector graphics backends will combine all images on a
# set of axes into a single composite image
'image.composite_image': [True, validate_bool],

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

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

0 comments on commit 2b9c228

Please sign in to comment.