bokeh.models.annotations¶
Renderers for various kinds of annotations that can be added to Bokeh plots
-
class
Annotation
(**kwargs)[source]¶ Bases:
bokeh.models.renderers.Renderer
Base class for all annotation models.
Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Arrow
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render arrows as an annotation.
-
end_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the end_x and end_y attributes. Interpreted as “data space” units by default.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_alpha
¶ property type:
NumberSpec
The line alpha values for the arrow body.
-
line_dash
¶ property type:
DashPattern
The line dash values for the arrow body.
-
line_width
¶ property type:
NumberSpec
The line width values for the arrow body.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
source
¶ property type:
Instance
(DataSource
)Local data source to use when rendering annotations on the plot.
-
start_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the start_x and start_y attributes. Interpreted as “data space” units by default.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
x_end
¶ property type:
NumberSpec
The x-coordinates to locate the end of the arrows.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default x-range.
-
x_start
¶ property type:
NumberSpec
The x-coordinates to locate the start of the arrows.
-
y_end
¶ property type:
NumberSpec
The y-coordinates to locate the end of the arrows.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default y-range.
-
y_start
¶ property type:
NumberSpec
The y-coordinates to locate the start of the arrows.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Band
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a filled area band along a dimension.
-
base
¶ property type:
PropertyUnitsSpec
The orthogonal coordinates of the upper and lower values.
-
dimension
¶ property type:
Enum
(Dimension
)The direction of the band can be specified by setting this property to “height” (
y
direction) or “width” (x
direction).
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_dash
¶ property type:
DashPattern
The line dash values for the band.
-
lower
¶ property type:
PropertyUnitsSpec
The coordinates of the lower portion of the filled area band.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
source
¶ property type:
Instance
(DataSource
)Local data source to use when rendering annotations on the plot.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
upper
¶ property type:
PropertyUnitsSpec
The coordinates of the upper portion of the filled area band.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default x-range.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default y-range.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
BoxAnnotation
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a shaded rectangular region as an annotation.
-
bottom
¶ property type:
Either
(Auto
,NumberSpec
)The y-coordinates of the bottom edge of the box annotation.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
bottom_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the bottom attribute. Interpreted as “data space” units by default.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
left
¶ property type:
Either
(Auto
,NumberSpec
)The x-coordinates of the left edge of the box annotation.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
left_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the left attribute. Interpreted as “data space” units by default.
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_dash
¶ property type:
DashPattern
The line dash values for the box.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the box is rendered as a canvas element or as an css element overlaid on the canvas. The default mode is “canvas”.
Warning
The line_dash and line_dash_offset attributes aren’t supported if the render_mode is set to “css”
-
right
¶ property type:
Either
(Auto
,NumberSpec
)The x-coordinates of the right edge of the box annotation.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
right_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the right attribute. Interpreted as “data space” units by default.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
top
¶ property type:
Either
(Auto
,NumberSpec
)The y-coordinates of the top edge of the box annotation.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
top_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the top attribute. Interpreted as “data space” units by default.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering box annotations on the plot. If unset, use the default x-range.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering box annotations on the plot. If unset, use the default y-range.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
ColorBar
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a color bar based on a color mapper.
-
bar_line_alpha
¶ property type:
NumberSpec
The line alpha for the color scale bar outline.
-
bar_line_dash
¶ property type:
DashPattern
The line dash for the color scale bar outline.
-
bar_line_width
¶ property type:
NumberSpec
The line width for the color scale bar outline.
-
border_line_dash
¶ property type:
DashPattern
The line dash for the color bar border outline.
-
color_mapper
¶ property type:
Instance
(ContinuousColorMapper
)A continuous color mapper containing a color palette to render.
Warning
If the low and high attributes of the
ColorMapper
aren’t set, ticks and tick labels won’t be rendered. Additionally, if aLogTicker
is passed to the ticker argument and either or both of the logarithms of low and high values of the color_mapper are non-numeric (i.e. low=0), the tick and tick labels won’t be rendered.
-
formatter
¶ property type:
Instance
(TickFormatter
)A
TickFormatter
to use for formatting the visual appearance of ticks.
-
height
¶ property type:
Either
(Auto
,Int
)The height (in pixels) that the color scale should occupy.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
label_standoff
¶ property type:
Int
The distance (in pixels) to separate the tick labels from the color bar.
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
location
¶ property type:
Either
(Enum
(LegendLocation
),Tuple
(Float
,Float
) )The location where the color bar should draw itself. It’s either one of
bokeh.core.enums.LegendLocation
’s enumerated values, or a(x, y)
tuple indicating an absolute location absolute location in screen coordinates (pixels from the bottom-left corner).Warning
If the color bar is placed in a side panel, the location will likely have to be set to (0,0).
-
major_label_overrides
¶ property type:
Dict
(Either
(Float
,String
),String
)Provide explicit tick label values for specific tick locations that override normal formatting.
-
major_label_text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline of the major tick labels.
-
major_label_text_font_style
¶ property type:
Enum
(FontStyle
)The text font style of the major tick labels.
-
major_tick_in
¶ property type:
Int
The distance (in pixels) that major ticks should extend into the main plot area.
-
major_tick_line_dash
¶ property type:
DashPattern
The line dash of the major ticks.
-
major_tick_out
¶ property type:
Int
The distance (in pixels) that major ticks should extend out of the main plot area.
-
minor_tick_in
¶ property type:
Int
The distance (in pixels) that minor ticks should extend into the main plot area.
-
minor_tick_line_dash
¶ property type:
DashPattern
The line dash of the minor ticks.
-
minor_tick_out
¶ property type:
Int
The distance (in pixels) that major ticks should extend out of the main plot area.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
orientation
¶ property type:
Enum
(Orientation
)Whether the color bar should be oriented vertically or horizontally.
-
padding
¶ property type:
Int
Amount of padding (in pixels) between the color scale and color bar border.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
ticker
¶ property type:
Instance
(ContinuousTicker
)A Ticker to use for computing locations of axis components.
-
title_standoff
¶ property type:
Int
The distance (in pixels) to separate the title from the color bar.
-
title_text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline values for the title text.
-
title_text_font_style
¶ property type:
Enum
(FontStyle
)The text font style values for the title text.
-
width
¶ property type:
Either
(Auto
,Int
)The width (in pixels) that the color scale should occupy.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Label
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.TextAnnotation
Render a single text label as an annotation.
Label
will render a single text label at givenx
andy
coordinates, which can be in either screen (pixel) space, or data (axis range) space.The label can also be configured with a screen space offset from
x
andy
, by using thex_offset
andy_offset
properties.Additionally, the label can be rotated with the
angle
property.There are also standard text, fill, and line properties to control the appearance of the text, its background, as well as the rectangular bounding box border.
-
angle
¶ property type:
Angle
The angle to rotate the text, as measured from the horizontal.
Warning
The center of rotation for canvas and css render_modes is different. For render_mode=”canvas” the label is rotated from the top-left corner of the annotation, while for render_mode=”css” the annotation is rotated around it’s center.
-
angle_units
¶ property type:
Enum
(AngleUnits
)Acceptable values for units are
"rad"
and"deg"
-
border_line_dash
¶ property type:
DashPattern
The line dash values for the text bounding box.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the text is rendered as a canvas element or as a CSS element overlaid on the canvas. The default mode is “canvas”.
Note
The CSS labels won’t be present in the output using the “save” tool.
Warning
Not all visual styling properties are supported if the render_mode is set to “css”. The border_line_dash property isn’t fully supported and border_line_dash_offset isn’t supported at all. Setting text_alpha will modify the opacity of the entire background box and border in addition to the text. Finally, clipping Label annotations inside of the plot area isn’t supported in “css” mode.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline values for the text.
-
x
¶ property type:
Float
The x-coordinate in screen coordinates to locate the text anchors.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
x_offset
¶ property type:
Float
Offset value to apply to the x-coordinate.
This is useful, for instance, if it is desired to “float” text a fixed distance in screen units from a given data position.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen location when rendering an annotation on the plot. If unset, use the default x-range.
-
x_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the x attribute. Interpreted as “data space” units by default.
-
y
¶ property type:
Float
The y-coordinate in screen coordinates to locate the text anchors.
Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
y_offset
¶ property type:
Float
Offset value to apply to the y-coordinate.
This is useful, for instance, if it is desired to “float” text a fixed distance in screen units from a given data position.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen location when rendering an annotation on the plot. If unset, use the default y-range.
-
y_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the y attribute. Interpreted as “data space” units by default.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
LabelSet
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.TextAnnotation
Render multiple text labels as annotations.
LabelSet
will render multiple text labels at givenx
andy
coordinates, which can be in either screen (pixel) space, or data (axis range) space. In this case (as opposed to the singleLabel
model),x
andy
can also be the name of a column from aColumnDataSource
, in which case the labels will be “vectorized” using coordinate values from the specified columns.The label can also be configured with a screen space offset from
x
andy
, by using thex_offset
andy_offset
properties. These offsets may be vectorized by giving the name of a data source column.Additionally, the label can be rotated with the
angle
property (which may also be a column name.)There are also standard text, fill, and line properties to control the appearance of the text, its background, as well as the rectangular bounding box border.
The data source is provided by setting the
source
property.-
angle
¶ property type:
AngleSpec
The angles to rotate the text, as measured from the horizontal.
Warning
The center of rotation for canvas and css render_modes is different. For render_mode=”canvas” the label is rotated from the top-left corner of the annotation, while for render_mode=”css” the annotation is rotated around it’s center.
-
background_fill_alpha
¶ property type:
NumberSpec
The fill alpha values for the text bounding box.
-
border_line_alpha
¶ property type:
NumberSpec
The line alpha values for the text bounding box.
-
border_line_dash
¶ property type:
DashPattern
The line dash values for the text bounding box.
-
border_line_width
¶ property type:
NumberSpec
The line width values for the text bounding box.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the text is rendered as a canvas element or as a CSS element overlaid on the canvas. The default mode is “canvas”.
Note
The CSS labels won’t be present in the output using the “save” tool.
Warning
Not all visual styling properties are supported if the render_mode is set to “css”. The border_line_dash property isn’t fully supported and border_line_dash_offset isn’t supported at all. Setting text_alpha will modify the opacity of the entire background box and border in addition to the text. Finally, clipping Label annotations inside of the plot area isn’t supported in “css” mode.
-
source
¶ property type:
Instance
(DataSource
)Local data source to use when rendering annotations on the plot.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
text
¶ property type:
StringSpec
The text values to render.
-
text_alpha
¶ property type:
NumberSpec
The text alpha values for the text.
-
text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline values for the text.
-
text_font_size
¶ property type:
FontSizeSpec
The text font size values for the text.
-
x
¶ property type:
NumberSpec
The x-coordinates to locate the text anchors.
-
x_offset
¶ property type:
NumberSpec
Offset values to apply to the x-coordinates.
This is useful, for instance, if it is desired to “float” text a fixed distance in screen units from a given data position.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default x-range.
-
x_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the
xs
attribute. Interpreted as “data space” units by default.
-
y
¶ property type:
NumberSpec
The y-coordinates to locate the text anchors.
-
y_offset
¶ property type:
NumberSpec
Offset values to apply to the y-coordinates.
This is useful, for instance, if it is desired to “float” text a fixed distance in screen units from a given data position.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default y-range.
-
y_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the
ys
attribute. Interpreted as “data space” units by default.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Legend
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render informational legends for a plot.
-
border_line_dash
¶ property type:
DashPattern
The line dash for the legend border outline.
-
click_policy
¶ property type:
Enum
(LegendClickPolicy
)Defines what happens when a lengend’s item is clicked.
-
glyph_height
¶ property type:
Int
The height (in pixels) that the rendered legend glyph should occupy.
-
inactive_fill_alpha
¶ property type:
Percent
The fill alpha for the legend item style when inactive. These control an overlay on the item that can be used to obscure it when the corresponding glyph is inactive (e.g. by making it semi-transparent).
-
inactive_fill_color
¶ property type:
Color
The fill color for the legend item style when inactive. These control an overlay on the item that can be used to obscure it when the corresponding glyph is inactive (e.g. by making it semi-transparent).
-
items
¶ property type:
List
(Instance
(LegendItem
) )A list of
LegendItem
instances to be rendered in the legend.This can be specified explicitly, for instance:
legend = Legend(items=[ LegendItem(label="sin(x)" , renderers=[r0, r1]), LegendItem(label="2*sin(x)" , renderers=[r2]), LegendItem(label="3*sin(x)" , renderers=[r3, r4]) ])
But as a convenience, can also be given more compactly as a list of tuples:
legend = Legend(items=[ ("sin(x)" , [r0, r1]), ("2*sin(x)" , [r2]), ("3*sin(x)" , [r3, r4]) ])
where each tuple is of the form: (label, renderers).
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
label_height
¶ property type:
Int
The minimum height (in pixels) of the area that legend labels should occupy.
-
label_standoff
¶ property type:
Int
The distance (in pixels) to separate the label from its associated glyph.
-
label_text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline for the legend labels.
-
label_width
¶ property type:
Int
The minimum width (in pixels) of the area that legend labels should occupy.
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
location
¶ property type:
Either
(Enum
(LegendLocation
),Tuple
(Float
,Float
) )The location where the legend should draw itself. It’s either one of
bokeh.core.enums.LegendLocation
’s enumerated values, or a(x, y)
tuple indicating an absolute location absolute location in screen coordinates (pixels from the bottom-left corner).
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
orientation
¶ property type:
Enum
(Orientation
)Whether the legend entries should be placed vertically or horizontally when they are drawn.
-
padding
¶ property type:
Int
Amount of padding around the contents of the legend. Only applicable when when border is visible, otherwise collapses to 0.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
title_text_baseline
¶ property type:
Enum
(TextBaseline
)The text baseline values for the title text.
-
title_text_font_style
¶ property type:
Enum
(FontStyle
)The text font style values for the title text.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
LegendItem
(*args, **kwargs)[source]¶ Bases:
bokeh.model.Model
-
index
¶ property type:
Int
The column data index to use for drawing the representative items.
If None (the default), then Bokeh will automatically choose an index to use. If the label does not refer to a data column name, this is typically the first data point in the data source. Otherwise, if the label does refer to a column name, the legend will have “groupby” behavior, and will choose and display representative points from every “group” in the column.
If set to a number, Bokeh will use that number as the index in all cases.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
label
¶ property type:
StringSpec
A label for this legend. Can be a string, or a column of a ColumnDataSource. If
label
is a field, then it must be in the renderers’ data_source.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
renderers
¶ property type:
List
(Instance
(GlyphRenderer
) )A list of the glyph renderers to draw in the legend. If
label
is a field, then all data_sources of renderers must be the same.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
PolyAnnotation
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a shaded polygonal region as an annotation.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_dash
¶ property type:
DashPattern
The line dash values for the polygon.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering box annotations on the plot. If unset, use the default x-range.
-
xs_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the
xs
attribute. Interpreted as “data space” units by default.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering box annotations on the plot. If unset, use the default y-range.
-
ys_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the
ys
attribute. Interpreted as “data space” units by default.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Slope
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a sloped line as an annotation.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_dash
¶ property type:
DashPattern
The line dash values for the line.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default x-range.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default y-range.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Span
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Render a horizontal or vertical line span.
-
dimension
¶ property type:
Enum
(Dimension
)The direction of the span can be specified by setting this property to “height” (
y
direction) or “width” (x
direction).
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
line_dash
¶ property type:
DashPattern
The line dash values for the span.
-
location
¶ property type:
Float
The location of the span, along
dimension
.Datetime values are also accepted, but note that they are immediately converted to milliseconds-since-epoch.
-
location_units
¶ property type:
Enum
(SpatialUnits
)The unit type for the location attribute. Interpreted as “data space” units by default.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the span is rendered as a canvas element or as a CSS element overlaid on the canvas. The default mode is “canvas”.
Warning
The line_dash and line_dash_offset attributes aren’t supported if the render_mode is set to “css”
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
x_range_name
¶ property type:
String
A particular (named) x-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default x-range.
-
y_range_name
¶ property type:
String
A particular (named) y-range to use for computing screen locations when rendering annotations on the plot. If unset, use the default y-range.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
TextAnnotation
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.Annotation
Base class for text annotation models such as labels and titles.
Note
This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the text is rendered as a canvas element or as a CSS element overlaid on the canvas. The default mode is “canvas”.
Note
The CSS labels won’t be present in the output using the “save” tool.
Warning
Not all visual styling properties are supported if the render_mode is set to “css”. The border_line_dash property isn’t fully supported and border_line_dash_offset isn’t supported at all. Setting text_alpha will modify the opacity of the entire background box and border in addition to the text. Finally, clipping Label annotations inside of the plot area isn’t supported in “css” mode.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[str, Any]¶ Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
-
query_properties_with_values
(query, include_defaults=True)¶ Query the properties values of
HasProps
instances with a predicate.- Parameters
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns
mapping of property names and values for matching properties
- Return type
-
references
()¶ Returns all
Models
that this object has references to.
-
remove_on_change
(attr, *callbacks)¶ Remove a callback from this object
-
select
(selector)¶ Query this object and all of its references for objects that match the given selector.
- Parameters
selector (JSON-like) –
- Returns
seq[Model]
-
select_one
(selector)¶ Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found :param selector: :type selector: JSON-like
- Returns
Model
-
set_from_json
(name, json, models=None, setter=None)¶ Set a property value on this object from JSON.
- Parameters
name – (str) : name of the attribute to set
json – (JSON-value) : value to set to the attribute to
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
set_select
(selector, updates)¶ Update objects that match a given selector with the specified attribute/value updates.
- Parameters
selector (JSON-like) –
updates (dict) –
- Returns
None
-
themed_values
()¶ Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
None
if no theme overrides any values for this instance.- Returns
dict or None
-
to_json
(include_defaults)¶ Returns a dictionary of the attributes of this object, containing only “JSON types” (string, number, boolean, none, dict, list).
References to other objects are serialized as “refs” (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
to_json_string
(include_defaults)¶ Returns a JSON string encoding the attributes of this object.
References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects.
There’s no corresponding
from_json_string()
because to deserialize an object is normally done in the context of a Document (since the Document can resolve references).For most purposes it’s best to serialize and deserialize entire documents.
- Parameters
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
-
trigger
(attr, old, new, hint=None, setter=None)¶
-
unapply_theme
()¶ Remove any themed values and restore defaults.
- Returns
None
-
update
(**kwargs)¶ Updates the object’s properties from the given keyword arguments.
- Returns
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
-
update_from_json
(json_attributes, models=None, setter=None)¶ Updates the object’s properties from a JSON attributes dictionary.
- Parameters
json_attributes – (JSON-dict) : attributes and values to update
models (dict or None, optional) –
Mapping of model ids to models (default: None)
This is needed in cases where the attributes to update also have values that have references.
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns
None
-
property
document
¶ The
Document
this model is attached to (can beNone
)
-
property
struct
¶ A Bokeh protocol “structure” of this model, i.e. a dict of the form:
{ 'type' : << view model name >> 'id' : << unique model id >> }
Additionally there may be a subtype field if this model is a subtype.
-
-
class
Title
(**kwargs)[source]¶ Bases:
bokeh.models.annotations.TextAnnotation
Render a single title box as an annotation.
-
align
¶ property type:
Enum
(TextAlign
)Alignment of the text in its enclosing space, along the direction of the text.
-
border_line_dash
¶ property type:
DashPattern
The line dash values for the text bounding box.
-
js_event_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of event names to lists of
CustomJS
callbacks.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_event
method:callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
-
js_property_callbacks
¶ property type:
Dict
(String
,List
(Instance
(CustomJS
) ) )A mapping of attribute names to lists of
CustomJS
callbacks, to be set up on BokehJS side when the document is created.Typically, rather then modifying this property directly, callbacks should be added using the
Model.js_on_change
method:callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
-
level
¶ property type:
Enum
(RenderLevel
)Specifies the level in which to paint this renderer.
-
name
¶ property type:
String
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.circle([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
-
offset
¶ property type:
Float
Offset the text by a number of pixels (can be positive or negative). Shifts the text in different directions based on the location of the title:
above: shifts title right
right: shifts title down
below: shifts title right
left: shifts title up
-
render_mode
¶ property type:
Enum
(RenderMode
)Specifies whether the text is rendered as a canvas element or as a CSS element overlaid on the canvas. The default mode is “canvas”.
Note
The CSS labels won’t be present in the output using the “save” tool.
Warning
Not all visual styling properties are supported if the render_mode is set to “css”. The border_line_dash property isn’t fully supported and border_line_dash_offset isn’t supported at all. Setting text_alpha will modify the opacity of the entire background box and border in addition to the text. Finally, clipping Label annotations inside of the plot area isn’t supported in “css” mode.
-
subscribed_events
¶ property type:
List
(String
)List of events that are subscribed to by Python callbacks. This is the set of events that will be communicated from BokehJS back to Python for this model.
-
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.circle([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJS
callbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
-
text_alpha
¶ property type:
NumberSpec
An alpha value to use to fill text with.
Acceptable values are floating point numbers between 0 (transparent) and 1 (opaque).
-
text_color
¶ property type:
ColorSpec
A color to use to fill text with.
Acceptable values are:
any of the 147 named CSS colors, e.g
'green'
,'indigo'
an RGB(A) hex value, e.g.,
'#FF0000'
,'#44444444'
a 3-tuple of integers (r,g,b) between 0 and 255
a 4-tuple of (r,g,b,a) where r,g,b are integers between 0..255 and a is between 0..1
-
text_font
¶ property type:
String
Name of a font to use for rendering text, e.g.,
'times'
,'helvetica'
.
-
text_font_style
¶ property type:
Enum
(FontStyle
)A style to use for rendering text.
Acceptable values are:
'normal'
normal text'italic'
italic text'bold'
bold text
-
text_line_height
¶ property type:
Float
How much additional space should be allocated for the title. The value is provided as a number, but should be treated as a percentage of font size. The default is 100%, which means no additional space will be used.
-
vertical_align
¶ property type:
Enum
(VerticalAlign
)Alignment of the text in its enclosing space, across the direction of the text.
-
apply_theme
(property_values)¶ Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasProps
instance should modify it).- Parameters
property_values (dict) – theme values to use in place of defaults
- Returns
None
-
classmethod
dataspecs
()¶ Collect the names of all
DataSpec
properties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
dataspecs_with_props
()¶ Collect a dict mapping the names of all
DataSpec
properties on this class to the associated properties.This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
equals
(other)¶ Structural equality of models.
- Parameters
other (HasProps) – the other instance to compare to
- Returns
True, if properties are structurally equal, otherwise False
-
js_link
(attr, other, other_attr, attr_selector=None)¶ Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a CustomJS callback to update one Bokeh model property whenever another changes value.
- Parameters
Added in version 1.1
- Raises
Examples
This code with
js_link
:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
-
js_on_change
(event, *callbacks)¶ Attach a
CustomJS
callback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name"
. As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"
automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource
, use the"stream"
event on the source:source.js_on_change('streaming', callback)
-
layout
(side, plot)¶
-
classmethod
lookup
(name)¶ Find the
PropertyDescriptor
for a Bokeh property on a class, given the property name.- Parameters
name (str) – name of the property to search for
- Returns
descriptor for property named
name
- Return type
-
on_change
(attr, *callbacks)¶ Add a callback on this object to trigger when
attr
changes.- Parameters
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns
None
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
-
classmethod
properties
(with_bases=True)¶ Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_containers
()¶ Collect the names of all container properties on this class.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
classmethod
properties_with_refs
()¶ Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
-
properties_with_values
(include_defaults: bool = True) → Dict[
-