Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif scheme is None:
if norm is None:
norm = mpl.colors.Normalize(vmin=hue.min(), vmax=hue.max())
cmap = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
colors = [cmap.to_rgba(v) for v in hue]
categories = None
self.k = None
else: # scheme is not None
if isinstance(scheme, str):
try:
if scheme == scheme.lower():
scheme = scheme.title()
scheme = getattr(mc, scheme)(hue)
except AttributeError:
opts = tuple(list(mc.CLASSIFIERS) + ['Categorical'])
raise ValueError(
f'Invalid scheme {scheme!r}. If specified as a string, scheme must be one '
f'of {opts}.'
)
self.k = len(scheme.bins)
if norm is None:
norm = mpl.colors.Normalize(vmin=scheme.yb.min(), vmax=scheme.yb.max())
cmap = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)
values = scheme(hue)
binedges = [scheme.yb.min()] + scheme.bins.tolist()
categories = [
'{0:g} - {1:g}'.format(binedges[i], binedges[i + 1])
for i in range(len(binedges) - 1)
]
colors = [cmap.to_rgba(v) for v in values]