Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_step_to_linear():
step = cm.StepColormap(['green', 'yellow', 'red'],
vmin=3., vmax=10.,
index=[3, 4, 8, 10], caption='step')
step.to_linear()
def test_simple_step():
step = cm.StepColormap(['green', 'yellow', 'red'],
vmin=3., vmax=10.,
index=[3, 4, 8, 10], caption='step')
step = cm.StepColormap(['r', 'y', 'g', 'c', 'b', 'm'])
step._repr_html_()
def __init__(self):
self._schemes = _schemes.copy()
self._colormaps = {key: StepColormap(val) for
key, val in _schemes.items()}
for key, val in _schemes.items():
setattr(self, key, StepColormap(val))
def scale(self, vmin=0., vmax=1.):
"""Transforms the colorscale so that the minimal and maximal values
fit the given parameters.
"""
return StepColormap(
self.colors,
index=[vmin + (vmax-vmin)*(x-self.vmin)*1./(self.vmax-self.vmin) for x in self.index], # noqa
vmin=vmin,
vmax=vmax,
caption=self.caption,
)
if color_data is not None and key_on is not None:
real_values = np.array(list(color_data.values()))
real_values = real_values[~np.isnan(real_values)]
_, bin_edges = np.histogram(real_values, bins=bins)
bins_min, bins_max = min(bin_edges), max(bin_edges)
if np.any((real_values < bins_min) | (real_values > bins_max)):
raise ValueError(
'All values are expected to fall into one of the provided '
'bins (or to be Nan). Please check the `bins` parameter '
'and/or your data.')
# We add the colorscale
nb_bins = len(bin_edges) - 1
color_range = color_brewer(fill_color, n=nb_bins)
self.color_scale = StepColormap(
color_range,
index=bin_edges,
vmin=bins_min,
vmax=bins_max,
caption=legend_name)
# then we 'correct' the last edge for numpy digitize
# (we add a very small amount to fake an inclusive right interval)
increasing = bin_edges[0] <= bin_edges[-1]
bin_edges[-1] = np.nextafter(
bin_edges[-1],
(1 if increasing else -1) * np.inf)
key_on = key_on[8:] if key_on.startswith('feature.') else key_on
def get_by_key(obj, key):
else:
scaled_cm = self.scale(vmin=min(index), vmax=max(index))
n = len(index)-1
if round_method == 'int':
index = [round(x) for x in index]
if round_method == 'log10':
index = [_base(x) for x in index]
colors = [scaled_cm.rgba_floats_tuple(index[i] * (1.-i/(n-1.)) +
index[i+1] * i/(n-1.)) for
i in range(n)]
return StepColormap(colors, index=index, vmin=index[0], vmax=index[-1])
def __init__(self):
self._schemes = _schemes.copy()
self._colormaps = {key: StepColormap(val) for
key, val in _schemes.items()}
for key, val in _schemes.items():
setattr(self, key, StepColormap(val))
def __init__(self, colors, index=None, vmin=0., vmax=1., caption=''):
super(StepColormap, self).__init__(vmin=vmin, vmax=vmax,
caption=caption)
n = len(colors)
if n < 1:
raise ValueError('You must provide at least 1 colors.')
if index is None:
self.index = [vmin + (vmax-vmin)*i*1./n for i in range(n+1)]
else:
self.index = list(index)
self.colors = [_parse_color(x) for x in colors]