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_simple_linear():
linear = cm.LinearColormap(['green', 'yellow', 'red'], vmin=3., vmax=10.)
linear = cm.LinearColormap(['red', 'orange', 'yellow', 'green'],
index=[0, 0.1, 0.9, 1.])
linear._repr_html_()
def __init__(self):
self._schemes = _schemes.copy()
self._colormaps = {key: LinearColormap(val) for
key, val in _schemes.items()}
for key, val in _schemes.items():
setattr(self, key, LinearColormap(val))
def __init__(self, positions, colors, colormap=None, nb_steps=12,
weight=None, opacity=None, **kwargs):
super(ColorLine, self).__init__(**kwargs)
self._name = 'ColorLine'
positions = validate_locations(positions)
if colormap is None:
cm = LinearColormap(['green', 'yellow', 'red'],
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
elif isinstance(colormap, LinearColormap):
cm = colormap.to_step(nb_steps)
elif isinstance(colormap, list) or isinstance(colormap, tuple):
cm = LinearColormap(colormap,
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
else:
cm = colormap
out = {}
for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): # noqa
out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
for key, val in out.items():
self.add_child(PolyLine(val, color=key, weight=weight, opacity=opacity)) # noqa
Parameters
----------
index : list of floats, default None
The values corresponding to each color in the output colormap.
It has to be sorted.
If None, a regular grid between `vmin` and `vmax` is created.
"""
if index is None:
n = len(self.index)-1
index = [self.index[i]*(1.-i/(n-1.))+self.index[i+1]*i/(n-1.) for
i in range(n)]
colors = [self.rgba_floats_tuple(x) for x in index]
return LinearColormap(colors, index=index,
vmin=self.vmin, vmax=self.vmax)
def __init__(self, positions, colors, colormap=None, nb_steps=12,
weight=None, opacity=None, **kwargs):
super(ColorLine, self).__init__(**kwargs)
self._name = 'ColorLine'
positions = validate_locations(positions)
if colormap is None:
cm = LinearColormap(['green', 'yellow', 'red'],
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
elif isinstance(colormap, LinearColormap):
cm = colormap.to_step(nb_steps)
elif isinstance(colormap, list) or isinstance(colormap, tuple):
cm = LinearColormap(colormap,
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
else:
cm = colormap
out = {}
for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): # noqa
out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
for key, val in out.items():
self.add_child(PolyLine(val, color=key, weight=weight, opacity=opacity)) # noqa
def scale(self, vmin=0., vmax=1.):
"""Transforms the colorscale so that the minimal and maximal values
fit the given parameters.
"""
return LinearColormap(
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,
)
def __init__(self, positions, colors, colormap=None, nb_steps=12,
weight=None, opacity=None, **kwargs):
super(ColorLine, self).__init__(**kwargs)
self._name = 'ColorLine'
positions = validate_locations(positions)
if colormap is None:
cm = LinearColormap(['green', 'yellow', 'red'],
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
elif isinstance(colormap, LinearColormap):
cm = colormap.to_step(nb_steps)
elif isinstance(colormap, list) or isinstance(colormap, tuple):
cm = LinearColormap(colormap,
vmin=min(colors),
vmax=max(colors),
).to_step(nb_steps)
else:
cm = colormap
out = {}
for (lat1, lng1), (lat2, lng2), color in zip(positions[:-1], positions[1:], colors): # noqa
out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
for key, val in out.items():