Skip to content

Commit f8b4bcc

Browse files
committed
Some more usage of _check_in_list.
1 parent c94d0ed commit f8b4bcc

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6573,17 +6573,12 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65736573
if bins is None:
65746574
bins = rcParams['hist.bins']
65756575

6576-
# Validate string inputs here so we don't have to clutter
6577-
# subsequent code.
6578-
if histtype not in ['bar', 'barstacked', 'step', 'stepfilled']:
6579-
raise ValueError("histtype %s is not recognized" % histtype)
6580-
6581-
if align not in ['left', 'mid', 'right']:
6582-
raise ValueError("align kwarg %s is not recognized" % align)
6583-
6584-
if orientation not in ['horizontal', 'vertical']:
6585-
raise ValueError(
6586-
"orientation kwarg %s is not recognized" % orientation)
6576+
# Validate string inputs here to avoid cluttering subsequent code.
6577+
cbook._check_in_list(['bar', 'barstacked', 'step', 'stepfilled'],
6578+
histtype=histtype)
6579+
cbook._check_in_list(['left', 'mid', 'right'], align=align)
6580+
cbook._check_in_list(['horizontal', 'vertical'],
6581+
orientation=orientation)
65876582

65886583
if histtype == 'barstacked' and not stacked:
65896584
stacked = True

lib/matplotlib/cm.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,13 @@ def get_cmap(name=None, lut=None):
167167
"""
168168
if name is None:
169169
name = mpl.rcParams['image.cmap']
170-
171170
if isinstance(name, colors.Colormap):
172171
return name
173-
174-
if name in cmap_d:
175-
if lut is None:
176-
return cmap_d[name]
177-
else:
178-
return cmap_d[name]._resample(lut)
172+
cbook._check_in_list(sorted(cmap_d), name=name)
173+
if lut is None:
174+
return cmap_d[name]
179175
else:
180-
raise ValueError(
181-
"Colormap %s is not recognized. Possible values are: %s"
182-
% (name, ', '.join(sorted(cmap_d))))
176+
return cmap_d[name]._resample(lut)
183177

184178

185179
class ScalarMappable(object):

0 commit comments

Comments
 (0)