From f8b4bccf5b6ebc9246220438b2a1e50d0cf24c38 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 1 Apr 2019 22:20:26 +0200 Subject: [PATCH] Some more usage of _check_in_list. --- lib/matplotlib/axes/_axes.py | 17 ++++++----------- lib/matplotlib/cm.py | 14 ++++---------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 4630a7568818..a2b55ac851c6 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6573,17 +6573,12 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, if bins is None: bins = rcParams['hist.bins'] - # Validate string inputs here so we don't have to clutter - # subsequent code. - if histtype not in ['bar', 'barstacked', 'step', 'stepfilled']: - raise ValueError("histtype %s is not recognized" % histtype) - - if align not in ['left', 'mid', 'right']: - raise ValueError("align kwarg %s is not recognized" % align) - - if orientation not in ['horizontal', 'vertical']: - raise ValueError( - "orientation kwarg %s is not recognized" % orientation) + # Validate string inputs here to avoid cluttering subsequent code. + cbook._check_in_list(['bar', 'barstacked', 'step', 'stepfilled'], + histtype=histtype) + cbook._check_in_list(['left', 'mid', 'right'], align=align) + cbook._check_in_list(['horizontal', 'vertical'], + orientation=orientation) if histtype == 'barstacked' and not stacked: stacked = True diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 26b1766e84dd..030612f724a2 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -167,19 +167,13 @@ def get_cmap(name=None, lut=None): """ if name is None: name = mpl.rcParams['image.cmap'] - if isinstance(name, colors.Colormap): return name - - if name in cmap_d: - if lut is None: - return cmap_d[name] - else: - return cmap_d[name]._resample(lut) + cbook._check_in_list(sorted(cmap_d), name=name) + if lut is None: + return cmap_d[name] else: - raise ValueError( - "Colormap %s is not recognized. Possible values are: %s" - % (name, ', '.join(sorted(cmap_d)))) + return cmap_d[name]._resample(lut) class ScalarMappable(object):