Skip to content

Commit 0c7ae5d

Browse files
authored
Merge pull request #13833 from anntzer/moreinlist
Some more usage of _check_in_list.
2 parents 8714c32 + f8b4bcc commit 0c7ae5d

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
@@ -6597,17 +6597,12 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65976597
if bins is None:
65986598
bins = rcParams['hist.bins']
65996599

6600-
# Validate string inputs here so we don't have to clutter
6601-
# subsequent code.
6602-
if histtype not in ['bar', 'barstacked', 'step', 'stepfilled']:
6603-
raise ValueError("histtype %s is not recognized" % histtype)
6604-
6605-
if align not in ['left', 'mid', 'right']:
6606-
raise ValueError("align kwarg %s is not recognized" % align)
6607-
6608-
if orientation not in ['horizontal', 'vertical']:
6609-
raise ValueError(
6610-
"orientation kwarg %s is not recognized" % orientation)
6600+
# Validate string inputs here to avoid cluttering subsequent code.
6601+
cbook._check_in_list(['bar', 'barstacked', 'step', 'stepfilled'],
6602+
histtype=histtype)
6603+
cbook._check_in_list(['left', 'mid', 'right'], align=align)
6604+
cbook._check_in_list(['horizontal', 'vertical'],
6605+
orientation=orientation)
66116606

66126607
if histtype == 'barstacked' and not stacked:
66136608
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)