本文整理匯總了Python中param.Number方法的典型用法代碼示例。如果您正苦於以下問題:Python param.Number方法的具體用法?Python param.Number怎麽用?Python param.Number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類param
的用法示例。
在下文中一共展示了param.Number方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_widget_from_param_instance_with_kwargs
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_widget_from_param_instance_with_kwargs():
class Test(param.Parameterized):
a = param.Number(default=3.14)
test = Test()
widget = FloatSlider.from_param(test.param.a, start=0.3, end=5.2)
assert isinstance(widget, FloatSlider)
assert widget.name == 'A'
assert widget.start == 0.3
assert widget.end == 5.2
assert widget.value == 3.14
test.a = 1.57
assert widget.value == 1.57
widget.value = 4.3
assert test.a == 4.3
示例2: test_action_param
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_action_param(document, comm):
class Test(param.Parameterized):
a = param.Action(lambda x: setattr(x, 'b', 2))
b = param.Number(default=1)
test = Test()
test_pane = Pane(test)
model = test_pane.get_root(document, comm=comm)
button = model.children[1]
assert isinstance(button, Button)
# Check that the action is actually executed
pn_button = test_pane.layout[1]
pn_button.clicks = 1
assert test.b == 2
示例3: test_param_label
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_param_label(document, comm):
class Test(param.Parameterized):
a = param.Number(default=1.2, bounds=(0, 5), label='A')
b = param.Action(label='B')
test = Test()
test_pane = Pane(test)
# Check updating label changes widget name
a_param = test.param['a']
a_param.label = 'B'
assert test_pane._widgets['a'].name == 'B'
b_param = test.param['b']
b_param.label = 'C'
assert test_pane._widgets['b'].name == 'C'
示例4: test_set_name
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_set_name(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
b = param.String(default='A')
pane = Param(Test(), name='First')
model = pane.get_root(document, comm=comm)
assert len(model.children) == 3
title, slider, text = model.children
assert isinstance(title, Div)
# Check setting name displays in as a title
assert title.text == '<b>First</b>'
assert isinstance(slider, Slider)
assert isinstance(text, TextInput)
pane.name = 'Second'
assert len(model.children) == 3
title, _, _ = model.children
assert isinstance(title, Div)
# Check the title updates with name
assert title.text == '<b>Second</b>'
示例5: test_set_display_threshold
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_set_display_threshold(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10), precedence=1)
b = param.String(default='A', precedence=2)
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 3
title, slider, text = model.children
assert isinstance(title, Div)
assert isinstance(slider, Slider)
assert isinstance(text, TextInput)
pane.display_threshold = 1.5
assert len(model.children) == 2
title, text = model.children
assert isinstance(title, Div)
assert isinstance(text, TextInput)
示例6: test_set_show_name
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_set_show_name(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 2
title, widget = model.children
assert isinstance(title, Div)
assert isinstance(widget, Slider)
pane.show_name = False
assert len(model.children) == 1
assert isinstance(model.children[0], Slider)
示例7: test_set_show_labels
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_set_show_labels(document, comm):
class Test(param.Parameterized):
a = param.Number(bounds=(0, 10))
pane = Param(Test())
model = pane.get_root(document, comm=comm)
assert len(model.children) == 2
title, widget = model.children
assert isinstance(title, Div)
assert isinstance(widget, Slider)
assert widget.title == 'A'
pane.show_labels = False
assert len(model.children) == 2
assert isinstance(model.children[1], Slider)
assert model.children[1].title == ''
示例8: compute_zoom_level
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def compute_zoom_level(bounds, domain, levels):
"""
Computes a zoom level given a bounds polygon, a polygon of the
overall domain and the number of zoom levels to divide the data
into.
Parameters
----------
bounds: shapely.geometry.Polygon
Polygon representing the area of the current viewport
domain: shapely.geometry.Polygon
Polygon representing the overall bounding region of the data
levels: int
Number of zoom levels to divide the domain into
Returns
-------
zoom_level: int
Integer zoom level
"""
area_fraction = min(bounds.area/domain.area, 1)
return int(min(round(np.log2(1/area_fraction)), levels))
示例9: define
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def define(cls, name, **kwargs):
"""
Utility to quickly and easily declare Stream classes. Designed
for interactive use such as notebooks and shouldn't replace
parameterized class definitions in source code that is imported.
Takes a stream class name and a set of keywords where each
keyword becomes a parameter. If the value is already a
parameter, it is simply used otherwise the appropriate parameter
type is inferred and declared, using the value as the default.
Supported types: bool, int, float, str, dict, tuple and list
"""
params = {'name': param.String(default=name)}
for k, v in kwargs.items():
kws = dict(default=v, constant=True)
if isinstance(v, param.Parameter):
params[k] = v
elif isinstance(v, bool):
params[k] = param.Boolean(**kws)
elif isinstance(v, int):
params[k] = param.Integer(**kws)
elif isinstance(v, float):
params[k] = param.Number(**kws)
elif isinstance(v, str):
params[k] = param.String(**kws)
elif isinstance(v, dict):
params[k] = param.Dict(**kws)
elif isinstance(v, tuple):
params[k] = param.Tuple(**kws)
elif isinstance(v, list):
params[k] = param.List(**kws)
elif isinstance(v, np.ndarray):
params[k] = param.Array(**kws)
else:
params[k] = param.Parameter(**kws)
# Dynamic class creation using type
return type(name, (Stream,), params)
示例10: test_XY_types
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_XY_types(self):
self.assertEqual(isinstance(self.XY.param['x'], param.Number),True)
self.assertEqual(isinstance(self.XY.param['y'], param.Number),True)
示例11: test_custom_types
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_custom_types(self):
self.assertEqual(isinstance(self.TypesTest.param['t'], param.Boolean),True)
self.assertEqual(isinstance(self.TypesTest.param['u'], param.Integer),True)
self.assertEqual(isinstance(self.TypesTest.param['v'], param.Number),True)
self.assertEqual(isinstance(self.TypesTest.param['w'], param.Tuple),True)
self.assertEqual(isinstance(self.TypesTest.param['x'], param.String),True)
self.assertEqual(isinstance(self.TypesTest.param['y'], param.List),True)
self.assertEqual(isinstance(self.TypesTest.param['z'], param.Array),True)
示例12: setUp
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def setUp(self):
super(TestParamsStream, self).setUp()
class Inner(param.Parameterized):
x = param.Number(default = 0)
y = param.Number(default = 0)
class InnerAction(Inner):
action = param.Action(lambda o: o.param.trigger('action'))
self.inner = Inner
self.inner_action = InnerAction
示例13: LiteralInputTyped
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def LiteralInputTyped(pobj):
if isinstance(pobj, param.Tuple):
return type(str('TupleInput'), (LiteralInput,), {'type': tuple})
elif isinstance(pobj, param.Number):
return type(str('NumberInput'), (LiteralInput,), {'type': (int, float)})
elif isinstance(pobj, param.Dict):
return type(str('DictInput'), (LiteralInput,), {'type': dict})
elif isinstance(pobj, param.List):
return type(str('ListInput'), (LiteralInput,), {'type': list})
return LiteralInput
示例14: test_instantiate_from_class
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_instantiate_from_class():
class Test(param.Parameterized):
a = param.Number()
assert isinstance(Pane(Test), Param)
示例15: test_instantiate_from_parameter
# 需要導入模塊: import param [as 別名]
# 或者: from param import Number [as 別名]
def test_instantiate_from_parameter():
class Test(param.Parameterized):
a = param.Number()
assert isinstance(Pane(Test.param.a), Param)