From cff9efd7426f5977cf47af76376934957e971afc Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 4 Mar 2015 20:25:49 -0500 Subject: [PATCH 1/2] BUG/API : fix color validation Possible fix for #4192. This adds a new validation (validate_color_or_None) method for color which allows None and restores `validate_color` to fail on None. This will allow selected color rcparams to be `None` (not `'None'`) which the library should interpret as "don't use this rcparam". --- lib/matplotlib/rcsetup.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index b25788da001e..d234634b3e25 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -235,6 +235,12 @@ def __call__(self, s): raise ValueError('Could not convert all entries to ints') +def validate_color_or_None(s): + if s is None: + return None + return validate_color(s) + + def validate_color(s): 'return a valid color arg' try: @@ -245,6 +251,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. @@ -595,7 +602,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], @@ -685,6 +692,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': [None, validate_color_or_None], + 'legend.edgecolor': [None, validate_color_or_None], ## tick properties 'xtick.major.size': [4, validate_float], # major xtick size in points From f034cdee8277787961b596c7837395d8970edca0 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Fri, 13 Mar 2015 21:40:37 -0400 Subject: [PATCH 2/2] MNT : try to fix optional/inherited rcparams Attempt to implement 'inherited' rcparams, that is rcparams that are only used if they are non-default. Re-introduces feature introduced in #3792 /92e608d655f1fa667fdf5bc3e99f950eb08f7c42 and reverted in c90469b913982ee83e48036c68a39d1884d84a3f --- lib/matplotlib/legend.py | 10 ++++++++++ lib/matplotlib/rcsetup.py | 11 ++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index c7423fb4518c..06702d8d3a9a 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -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"], diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index d234634b3e25..bca661cd3091 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -235,9 +235,10 @@ def __call__(self, s): raise ValueError('Could not convert all entries to ints') -def validate_color_or_None(s): - if s is None: - return None +def validate_color_or_inherit(s): + 'return a valid color arg' + if s == 'inherit': + return s return validate_color(s) @@ -692,8 +693,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': [None, validate_color_or_None], - 'legend.edgecolor': [None, validate_color_or_None], + '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