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_dynamic_operation_init_stream_params(self):
img = Image(sine_array(0,5))
stream = Stream.define('TestStream', bin_range=None)()
histogram(img, bin_range=(0, 1), streams=[stream], dynamic=True)
self.assertEqual(stream.bin_range, (0, 1))
def callback(x, y):
return Image(np.array([[0, 1], [2, 3]])) + Text(0, 0, 'Test')
stream = PointerXY()
def test_select_on_transposed_dataarray(self):
x = np.linspace(-3, 7, 53)
y = np.linspace(-5, 8, 89)
z = np.exp(-1*(x**2 + y[:, np.newaxis]**2))
array = xr.DataArray(z, coords=[y, x], dims=['x', 'y'])
img = Image(array)[1:3]
self.assertEqual(img['z'], Image(array.sel(x=slice(1, 3)))['z'])
def test_layout_instantiate_subplots(self):
layout = (Curve(range(10)) + Curve(range(10)) + Image(np.random.rand(10,10)) +
Curve(range(10)) + Curve(range(10)))
plot = plotly_renderer.get_plot(layout)
positions = [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3)]
self.assertEqual(sorted(plot.subplots.keys()), positions)
fn = lambda i: Image(sine_array(0,i))
dmap=DynamicMap(fn, kdims=[Dimension('dim', range=(0,10))])
def test_distribution_from_image(self):
dist = Distribution(Image(np.arange(5)*np.arange(5)[:, np.newaxis]), 'z')
self.assertEqual(dist.range(0), (0, 16))
fn = lambda i: Image(sine_array(0,i))
dmap=DynamicMap(fn, kdims=[Dimension('dim', range=(0,10))])
class VectorField(_Element, HvVectorField):
"""
A VectorField contains is a collection of vectors where each
vector has an associated position. The vectors should be specified
by defining an angle in radians and a magnitude.
"""
group = param.String(default='VectorField', constant=True)
vdims = param.List(default=[Dimension('Angle', cyclic=True, range=(0,2*np.pi)),
Dimension('Magnitude')], bounds=(1, None))
class LineContours(_Element, HvImage):
"""
Contours represents a 2D array of some quantity with
some associated coordinates, which may be discretized
into one or more line contours.
"""
vdims = param.List(default=[Dimension('z')], bounds=(1, 1))
group = param.String(default='LineContours')
class FilledContours(LineContours):
"""
Contours represents a 2D array of some quantity with
some associated coordinates, which may be discretized
into one or more filled contours.
Specifies the smallest allowed sampling interval along the x axis.""")
y_sampling = param.Number(default=None, doc="""
Specifies the smallest allowed sampling interval along the y axis.""")
target = param.ClassSelector(class_=Dataset, doc="""
A target Dataset which defines the desired x_range, y_range,
width and height.
""")
streams = param.List(default=[PlotSize, RangeXY], doc="""
List of streams that are applied if dynamic=True, allowing
for dynamic interaction with the plot.""")
element_type = param.ClassSelector(class_=(Dataset,), instantiate=False,
is_instance=False, default=Image,
doc="""
The type of the returned Elements, must be a 2D Dataset type.""")
precompute = param.Boolean(default=False, doc="""
Whether to apply precomputing operations. Precomputing can
speed up resampling operations by avoiding unnecessary
recomputation if the supplied element does not change between
calls. The cost of enabling this option is that the memory
used to represent this internal state is not freed between
calls.""")
@bothmethod
def instance(self_or_cls,**params):
filtered = {k:v for k,v in params.items() if k in self_or_cls.param}
inst = super(ResamplingOperation, self_or_cls).instance(**filtered)
inst._precomputed = {}
if element._plot_id in self._precomputed:
precomputed = self._precomputed[element._plot_id]
elif wireframe:
precomputed = self._precompute_wireframe(element, agg)
else:
precomputed = self._precompute(element, agg)
params = dict(get_param_values(element), kdims=[x, y],
datatype=['xarray'], vdims=[vdim])
if width == 0 or height == 0:
if width == 0: params['xdensity'] = 1
if height == 0: params['ydensity'] = 1
bounds = (x_range[0], y_range[0], x_range[1], y_range[1])
return Image((xs, ys, np.zeros((height, width))), bounds=bounds, **params)
if wireframe:
segments = precomputed['segments']
else:
simplices = precomputed['simplices']
pts = precomputed['vertices']
mesh = precomputed['mesh']
if precompute:
self._precomputed = {element._plot_id: precomputed}
cvs = ds.Canvas(plot_width=width, plot_height=height,
x_range=x_range, y_range=y_range)
if wireframe:
agg = cvs.line(segments, x=['x0', 'x1', 'x2', 'x3'],
y=['y0', 'y1', 'y2', 'y3'], axis=1,
agg=agg)