From dd3dba5a3dfc95e0237e97b0eb5eca687ec3ea19 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 22 Jun 2023 16:15:25 +0200 Subject: [PATCH] Do not check value of parameters from rcParam (and check rcParam before using them) --- lib/matplotlib/axes/_axes.py | 3 +-- lib/matplotlib/font_manager.py | 6 ++++-- lib/matplotlib/image.py | 6 ++++-- lib/matplotlib/lines.py | 6 ++---- lib/matplotlib/markers.py | 3 ++- lib/matplotlib/mlab.py | 10 ++++++---- lib/matplotlib/rcsetup.py | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 46fb69852286..7166f2921416 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2757,6 +2757,7 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge", if key in kwargs: raise ValueError( f"Passing {key!r} to bar_label() is not supported.") + _api.check_in_list(['edge', 'center'], label_type=label_type) a, b = self.yaxis.get_view_interval() y_inverted = a > b @@ -2768,8 +2769,6 @@ def bar_label(self, container, labels=None, *, fmt="%g", label_type="edge", def sign(x): return 1 if x >= 0 else -1 - _api.check_in_list(['edge', 'center'], label_type=label_type) - bars = container.patches errorbar = container.errorbar datavalues = container.datavalues diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index e7be2203bc12..308e48f1c81b 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -740,7 +740,8 @@ def set_style(self, style): """ if style is None: style = mpl.rcParams['font.style'] - _api.check_in_list(['normal', 'italic', 'oblique'], style=style) + else: + _api.check_in_list(['normal', 'italic', 'oblique'], style=style) self._slant = style def set_variant(self, variant): @@ -753,7 +754,8 @@ def set_variant(self, variant): """ if variant is None: variant = mpl.rcParams['font.variant'] - _api.check_in_list(['normal', 'small-caps'], variant=variant) + else: + _api.check_in_list(['normal', 'small-caps'], variant=variant) self._variant = variant def set_weight(self, weight): diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index c8d6f89a0621..3b0998848e2e 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -260,7 +260,8 @@ def __init__(self, ax, cm.ScalarMappable.__init__(self, norm, cmap) if origin is None: origin = mpl.rcParams['image.origin'] - _api.check_in_list(["upper", "lower"], origin=origin) + else: + _api.check_in_list(["upper", "lower"], origin=origin) self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) @@ -792,7 +793,8 @@ def set_interpolation_stage(self, s): """ if s is None: s = "data" # placeholder for maybe having rcParam - _api.check_in_list(['data', 'rgba'], s=s) + else: + _api.check_in_list(['data', 'rgba'], s=s) self._interpolation_stage = s self.stale = True diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index e18bd58bcdea..c8c89dd7c9b4 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -350,9 +350,6 @@ def __init__(self, xdata, ydata, *, if solid_joinstyle is None: solid_joinstyle = mpl.rcParams['lines.solid_joinstyle'] - if drawstyle is None: - drawstyle = 'default' - self._dashcapstyle = None self._dashjoinstyle = None self._solidjoinstyle = None @@ -1090,7 +1087,8 @@ def set_drawstyle(self, drawstyle): """ if drawstyle is None: drawstyle = 'default' - _api.check_in_list(self.drawStyles, drawstyle=drawstyle) + else: + _api.check_in_list(self.drawStyles, drawstyle=drawstyle) if self._drawstyle != drawstyle: self.stale = True # invalidate to trigger a recache of the path diff --git a/lib/matplotlib/markers.py b/lib/matplotlib/markers.py index e9bf7c02fb1f..00f5e1325c66 100644 --- a/lib/matplotlib/markers.py +++ b/lib/matplotlib/markers.py @@ -291,7 +291,8 @@ def _set_fillstyle(self, fillstyle): """ if fillstyle is None: fillstyle = mpl.rcParams['markers.fillstyle'] - _api.check_in_list(self.fillstyles, fillstyle=fillstyle) + else: + _api.check_in_list(self.fillstyles, fillstyle=fillstyle) self._fillstyle = fillstyle self._recache() diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 1948e6333e83..71a186fedf04 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -244,9 +244,10 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None, if mode is None or mode == 'default': mode = 'psd' - _api.check_in_list( - ['default', 'psd', 'complex', 'magnitude', 'angle', 'phase'], - mode=mode) + else: + _api.check_in_list( + ['default', 'psd', 'complex', 'magnitude', 'angle', 'phase'], + mode=mode) if not same_data and mode != 'psd': raise ValueError("x and y must be equal if mode is not 'psd'") @@ -262,7 +263,8 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None, sides = 'twosided' else: sides = 'onesided' - _api.check_in_list(['default', 'onesided', 'twosided'], sides=sides) + else: + _api.check_in_list(['default', 'onesided', 'twosided'], sides=sides) # zero pad x and y up to NFFT if they are shorter than NFFT if len(x) < NFFT: diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index f75ad21acc59..5103c68f7ff0 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -930,8 +930,8 @@ def _convert_validator_spec(key, conv): ## font props "font.family": validate_stringlist, # used by text object - "font.style": validate_string, - "font.variant": validate_string, + "font.style": ['normal', 'italic', 'oblique'], + "font.variant": ['normal', 'small-caps'], "font.stretch": validate_fontstretch, "font.weight": validate_fontweight, "font.size": validate_float, # Base font size in points