本文整理汇总了Python中holoviews.core.spaces.DynamicMap.apply方法的典型用法代码示例。如果您正苦于以下问题:Python DynamicMap.apply方法的具体用法?Python DynamicMap.apply怎么用?Python DynamicMap.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类holoviews.core.spaces.DynamicMap
的用法示例。
在下文中一共展示了DynamicMap.apply方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deep_apply_transform_element_type
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
def test_deep_apply_transform_element_type(self):
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
dmap[10]
mapped = dmap.apply(lambda x: Scatter(x))
area = mapped[11]
self.assertEqual(area, Scatter(fn(11)))
示例2: test_deep_apply_parameterized_method_with_dependency_and_static_kwarg
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
def test_deep_apply_parameterized_method_with_dependency_and_static_kwarg(self):
class Test(param.Parameterized):
label = param.String(default='label')
@param.depends('label')
def relabel(self, obj, group):
return obj.relabel(self.label.title(), group)
test = Test()
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(test.relabel, group='Group')
curve = fn(10)
self.assertEqual(mapped[10], curve.relabel('Label', 'Group'))
test.label = 'new label'
self.assertEqual(mapped[10], curve.relabel('New Label', 'Group'))
示例3: test_deep_map_apply_parameterized_method_with_stream_kwarg
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
def test_deep_map_apply_parameterized_method_with_stream_kwarg(self):
class Test(param.Parameterized):
label = param.String(default='label')
@param.depends('label')
def value(self):
return self.label.title()
test = Test()
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(lambda x, label: x.relabel(label), label=test.value)
curve = fn(10)
self.assertEqual(mapped[10], curve.relabel('Label'))
test.label = 'new label'
self.assertEqual(mapped[10], curve.relabel('New Label'))
示例4: TestApplyDynamicMap
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
class TestApplyDynamicMap(ComparisonTestCase):
def setUp(self):
self.element = Curve([1, 2, 3])
self.dmap_unsampled = DynamicMap(lambda i: Curve([0, 1, i]), kdims='Y')
self.dmap = self.dmap_unsampled.redim.values(Y=[0, 1, 2])
def test_dmap_apply_not_dynamic_unsampled(self):
with self.assertRaises(ValueError):
self.dmap_unsampled.apply(lambda x: x.relabel('Test'), dynamic=False)
def test_dmap_apply_not_dynamic(self):
applied = self.dmap.apply(lambda x: x.relabel('Test'), dynamic=False)
self.assertEqual(applied, HoloMap(self.dmap[[0, 1, 2]]).relabel('Test'))
def test_dmap_apply_not_dynamic_with_kwarg(self):
applied = self.dmap.apply(lambda x, label: x.relabel(label), dynamic=False, label='Test')
self.assertEqual(applied, HoloMap(self.dmap[[0, 1, 2]]).relabel('Test'))
def test_dmap_apply_not_dynamic_with_instance_param(self):
pinst = ParamClass()
applied = self.dmap.apply(lambda x, label: x.relabel(label), label=pinst.param.label, dynamic=False)
self.assertEqual(applied, HoloMap(self.dmap[[0, 1, 2]]).relabel('Test'))
def test_dmap_apply_not_dynamic_with_param_method(self):
pinst = ParamClass()
applied = self.dmap.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label, dynamic=False)
self.assertEqual(applied, HoloMap(self.dmap[[0, 1, 2]]).relabel('Test!'))
def test_dmap_apply_dynamic(self):
applied = self.dmap.apply(lambda x: x.relabel('Test'))
self.assertEqual(len(applied.streams), 0)
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
def test_element_apply_method_as_string(self):
applied = self.dmap.apply('relabel', label='Test')
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
def test_dmap_apply_dynamic_with_kwarg(self):
applied = self.dmap.apply(lambda x, label: x.relabel(label), label='Test')
self.assertEqual(len(applied.streams), 0)
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
def test_dmap_apply_dynamic_with_instance_param(self):
pinst = ParamClass()
applied = self.dmap.apply(lambda x, label: x.relabel(label), label=pinst.param.label)
# Check stream
self.assertEqual(len(applied.streams), 1)
stream = applied.streams[0]
self.assertIsInstance(stream, Params)
self.assertEqual(stream.parameterized, pinst)
self.assertEqual(stream.parameters, [pinst.param.label])
# Check results
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
pinst.label = 'Another label'
self.assertEqual(applied[1], self.dmap[1].relabel('Another label'))
def test_dmap_apply_method_as_string_with_instance_param(self):
pinst = ParamClass()
applied = self.dmap.apply('relabel', label=pinst.param.label)
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
pinst.label = 'Another label'
self.assertEqual(applied[1], self.dmap[1].relabel('Another label'))
def test_dmap_apply_param_method_with_dependencies(self):
pinst = ParamClass()
applied = self.dmap.apply(pinst.apply_label)
# Check stream
self.assertEqual(len(applied.streams), 1)
stream = applied.streams[0]
self.assertIsInstance(stream, ParamMethod)
self.assertEqual(stream.parameterized, pinst)
self.assertEqual(stream.parameters, [pinst.param.label])
# Check results
self.assertEqual(applied[1], self.dmap[1].relabel('Test'))
pinst.label = 'Another label'
self.assertEqual(applied[1], self.dmap[1].relabel('Another label'))
def test_dmap_apply_dynamic_with_param_method(self):
pinst = ParamClass()
applied = self.dmap.apply(lambda x, label: x.relabel(label), label=pinst.dynamic_label)
# Check stream
self.assertEqual(len(applied.streams), 1)
stream = applied.streams[0]
self.assertIsInstance(stream, ParamMethod)
self.assertEqual(stream.parameterized, pinst)
self.assertEqual(stream.parameters, [pinst.param.label])
# Check result
self.assertEqual(applied[1], self.dmap[1].relabel('Test!'))
pinst.label = 'Another label'
self.assertEqual(applied[1], self.dmap[1].relabel('Another label!'))
示例5: test_deep_map_apply_element_function_with_stream_kwarg
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
def test_deep_map_apply_element_function_with_stream_kwarg(self):
stream = Stream.define('Test', label='New label')()
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(lambda x, label: x.relabel(label), streams=[stream])
self.assertEqual(mapped[10], fn(10).relabel('New label'))
示例6: test_deep_apply_element_function
# 需要导入模块: from holoviews.core.spaces import DynamicMap [as 别名]
# 或者: from holoviews.core.spaces.DynamicMap import apply [as 别名]
def test_deep_apply_element_function(self):
fn = lambda i: Curve(np.arange(i))
dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
mapped = dmap.apply(lambda x: x.clone(x.data*2))
curve = fn(10)
self.assertEqual(mapped[10], curve.clone(curve.data*2))