Models for describing different kinds of ranges of values in different kinds of spaces (e.g., continuous or categorical) and with options for “auto sizing”.
DataRange
Bases: bokeh.models.ranges.Range
bokeh.models.ranges.Range
A base class for all data range types.
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 ) ) )
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:
Model.js_on_event
callback = CustomJS(code="console.log('tap event occurred')") plot.js_on_event('tap', callback)
js_property_callbacks
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:
Model.js_on_change
callback = CustomJS(code="console.log('stuff')") plot.x_range.js_on_change('start', callback)
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', ...)]
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.
names
property type: List ( String )
A list of names to query for. If set, only renderers that have a matching value for their name attribute will be used for autoranging.
renderers
property type: List ( Instance ( Renderer ) )
Renderer
An explicit list of renderers to autorange against. If unset, defaults to all renderers on a plot.
subscribed_events
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.
tags
property type: List ( Any )
Any
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.
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
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).
HasProps
property_values (dict) – theme values to use in place of defaults
None
dataspecs
Collect the names of all DataSpec properties on this class.
DataSpec
This method always traverses the class hierarchy and includes properties defined on any parent classes.
names of DataSpec properties
set[str]
dataspecs_with_props
Collect a dict mapping the names of all DataSpec properties on this class to the associated properties.
mapping of names and DataSpec properties
dict[str, DataSpec]
equals
Structural equality of models.
other (HasProps) – the other instance to compare to
True, if properties are structurally equal, otherwise False
js_link
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.
attr (str) – The name of a Bokeh property on this model
other (Model) – A Bokeh model to link to self.attr
other_attr (str) – The property on other to link together
other
attr_selector (Union[int, str]) – The index to link an item in a subscriptable attr
attr
Added in version 1.1
ValueError –
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
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:
"change:property_name"
"change:"
# 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:
ColumnDataSource
"stream"
source.js_on_change('streaming', callback)
layout
lookup
Find the PropertyDescriptor for a Bokeh property on a class, given the property name.
PropertyDescriptor
name (str) – name of the property to search for
descriptor for property named name
on_change
Add a callback on this object to trigger when attr changes.
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
Example:
widget.on_change('value', callback1, callback2, ..., callback_n)
properties
Collect the names of properties on this class.
This method optionally traverses the class hierarchy and includes properties defined on any parent classes.
with_bases (bool, optional) – Whether to include properties defined on parent classes in the results. (default: True)
property names
properties_containers
Collect the names of all container properties on this class.
names of container properties
properties_with_refs
Collect the names of all properties on this class that also have references.
names of properties that have references
properties_with_values
Collect a dict mapping property names to their values.
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.
include_defaults (bool, optional) – Whether to include properties that haven’t been explicitly set since the object was created. (default: True)
mapping from property names to their values
dict
query_properties_with_values
Query the properties values of HasProps instances with a predicate.
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)
mapping of property names and values for matching properties
references
Returns all Models that this object has references to.
Models
remove_on_change
Remove a callback from this object
select
Query this object and all of its references for objects that match the given selector.
selector (JSON-like) –
seq[Model]
select_one
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
Model
set_from_json
Set a property value on this object from JSON.
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.
set_select
Update objects that match a given selector with the specified attribute/value updates.
updates (dict) –
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.
dict or None
to_json
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).
from_json()
For most purposes it’s best to serialize and deserialize entire documents.
include_defaults (bool) – whether to include attributes that haven’t been changed from the default
to_json_string
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).
from_json_string()
trigger
unapply_theme
Remove any themed values and restore defaults.
update
Updates the object’s properties from the given keyword arguments.
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
Updates the object’s properties from a JSON attributes dictionary.
json_attributes – (JSON-dict) : attributes and values to update
document
The Document this model is attached to (can be None)
Document
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.
{ "id": "15608", "js_event_callbacks": {}, "js_property_callbacks": {}, "name": null, "names": [], "renderers": [], "subscribed_events": [], "tags": [] }
DataRange1d
Bases: bokeh.models.ranges.DataRange
bokeh.models.ranges.DataRange
An auto-fitting range in a continuous scalar dimension.
By default the start and end of the range automatically assume min and max values of the data for associated renderers.
start
end
bounds
property type: MinMaxBounds
MinMaxBounds
The bounds that the range is allowed to go to. Typically used to prevent the user from panning/zooming/etc away from the data.
By default, the bounds will be None, allowing your plot to pan/zoom as far as you want. If bounds are ‘auto’ they will be computed to be the same as the start and end of the DataRange1d.
Bounds are provided as a tuple of (min, max) so regardless of whether your range is increasing or decreasing, the first item should be the minimum value of the range and the second item should be the maximum. Setting min > max will result in a ValueError.
(min, max)
min > max
ValueError
If you only want to constrain one end of the plot, you can set min or max to None e.g. DataRange1d(bounds=(None, 12))
min
max
DataRange1d(bounds=(None, 12))
default_span
property type: Either ( Float , TimeDelta )
Either
Float
TimeDelta
A default width for the interval, in case start is equal to end (if used with a log axis, default_span is in powers of 10).
property type: Either ( Float , Datetime , TimeDelta )
Datetime
An explicitly supplied range end. If provided, will override automatically computed end value.
flipped
property type: Bool
Bool
Whether the range should be “flipped” from its normal direction when auto-ranging.
follow
property type: Enum ( StartEnd )
Enum
StartEnd
Configure the data to follow one or the other data extreme, with a maximum range size of follow_interval.
follow_interval
If set to "start" then the range will adjust so that start always corresponds to the minimum data value (or maximum, if flipped is True).
"start"
True
If set to "end" then the range will adjust so that end always corresponds to the maximum data value (or minimum, if flipped is True).
"end"
If set to None (default), then auto-ranging does not follow, and the range will encompass both the minimum and maximum data values.
follow cannot be used with bounds, and if set, bounds will be set to None.
If follow is set to "start" or "end" then the range will always be constrained to that:
abs(r.start - r.end) <= follow_interval
is maintained.
max_interval
The level that the range is allowed to zoom out, expressed as the maximum visible interval. Note that bounds can impose an implicit constraint on the maximum interval as well.
min_interval
The level that the range is allowed to zoom in, expressed as the minimum visible interval. If set to None (default), the minimum interval is not bound.
only_visible
If True, renderers that that are not visible will be excluded from automatic bounds computations.
range_padding
How much padding to add around the computed data bounds.
When range_padding_units is set to "percent", the span of the range span is expanded to make the range range_padding percent larger.
range_padding_units
"percent"
When range_padding_units is set to "absolute", the start and end of the range span are extended by the amount range_padding.
"absolute"
property type: Enum ( PaddingUnits )
PaddingUnits
Whether the range_padding should be interpreted as a percentage, or as an absolute quantity. (default: "percent")
An explicitly supplied range start. If provided, will override automatically computed start value.
{ "bounds": null, "default_span": 2.0, "end": null, "flipped": false, "follow": null, "follow_interval": null, "id": "15616", "js_event_callbacks": {}, "js_property_callbacks": {}, "max_interval": null, "min_interval": null, "name": null, "names": [], "only_visible": false, "range_padding": 0.1, "range_padding_units": "percent", "renderers": [], "start": null, "subscribed_events": [], "tags": [] }
FactorRange
A Range of values for a categorical dimension.
In addition to supplying factors as a keyword argument to the FactorRange initializer, you may also instantiate with a sequence of positional arguments:
factors
FactorRange("foo", "bar") # equivalent to FactorRange(factors=["foo", "bar"])
Users will normally supply categorical values directly:
p.circle(x=["foo", "bar"], ...)
BokehJS will create a mapping from "foo" and "bar" to a numerical coordinate system called synthetic coordinates. In the simplest cases, factors are separated by a distance of 1.0 in synthetic coordinates, however the exact mapping from factors to synthetic coordinates is affected by he padding properties as well as whether the number of levels the factors have.
"foo"
"bar"
Users typically do not need to worry about the details of this mapping, however it can be useful to fine tune positions by adding offsets. When supplying factors as coordinates or values, it is possible to add an offset in the synthetic coordinate space by adding a final number value to a factor tuple. For example:
p.circle(x=[("foo", 0.3), ...], ...)
will position the first circle at an x position that is offset by adding 0.3 to the synthetic coordinate for "foo".
x
The bounds (in synthetic coordinates) that the range is allowed to go to. Typically used to prevent the user from panning/zooming/etc away from the data.
Synthetic coordinates are only computed in the browser, based on the factors and various padding properties. Some experimentation may be required to arrive at bounds suitable for specific situations.
By default, the bounds will be None, allowing your plot to pan/zoom as far as you want. If bounds are ‘auto’ they will be computed to be the same as the start and end of the FactorRange.
property type: Float
The end of the range, in synthetic coordinates.
Synthetic coordinates are only computed in the browser, based on the factors and various padding properties. The value of end will only be available in situations where bidirectional communication is available (e.g. server, notebook).
factor_padding
How much padding to add in between all lowest-level factors. When factor_padding is non-zero, every factor in every group will have the padding value applied.
property type: Either ( Seq ( String ), Seq ( Tuple ( String , String ) ), Seq ( Tuple ( String , String , String ) ) )
Seq
Tuple
A sequence of factors to define this categorical range.
Factors may have 1, 2, or 3 levels. For 1-level factors, each factor is simply a string. For example:
FactorRange(factors=["sales", "marketing", "engineering"])
defines a range with three simple factors that might represent different units of a business.
For 2- and 3- level factors, each factor is a tuple of strings:
FactorRange(factors=[ ["2016", "sales'], ["2016", "marketing'], ["2016", "engineering"], ["2017", "sales'], ["2017", "marketing'], ["2017", "engineering"], ])
defines a range with six 2-level factors that might represent the three business units, grouped by year.
Note that factors and sub-factors may only be strings.
group_padding
How much padding to add in between top-level groups of factors. This property only applies when the overall range factors have either two or three levels. For example, with:
FactorRange(factors=[["foo", "1'], ["foo", "2'], ["bar", "1"]])
The top level groups correspond to "foo"` and ``"bar", and the group padding will be applied between the factors ["foo", "2'] and ["bar", "1"]
"foo"` and ``"bar"
["foo", "2']
["bar", "1"]
The level that the range is allowed to zoom out, expressed as the maximum visible interval in synthetic coordinates.. Note that bounds can impose an implicit constraint on the maximum interval as well.
The default “width” of a category is 1.0 in synthetic coordinates. However, the distance between factors is affected by the various padding properties and whether or not factors are grouped.
The level that the range is allowed to zoom in, expressed as the minimum visible interval in synthetic coordinates. If set to None (default), the minimum interval is not bounded.
How much padding to add around the outside of computed range bounds.
The start of the range, in synthetic coordinates.
Synthetic coordinates are only computed in the browser, based on the factors and various padding properties. The value of start will only be available in situations where bidirectional communication is available (e.g. server, notebook).
subgroup_padding
How much padding to add in between mid-level groups of factors. This property only applies when the overall factors have three levels. For example with:
FactorRange(factors=[ ['foo', 'A', '1'], ['foo', 'A', '2'], ['foo', 'A', '3'], ['foo', 'B', '2'], ['bar', 'A', '1'], ['bar', 'A', '2'] ])
This property dictates how much padding to add between the three factors in the [‘foo’, ‘A’] group, and between the two factors in the the [bar]
{ "bounds": null, "factor_padding": 0.0, "factors": [], "group_padding": 1.4, "id": "15636", "js_event_callbacks": {}, "js_property_callbacks": {}, "max_interval": null, "min_interval": null, "name": null, "range_padding": 0, "range_padding_units": "percent", "subgroup_padding": 0.8, "subscribed_events": [], "tags": [] }
Range
Bases: bokeh.model.Model
bokeh.model.Model
A base class for all range types.
{ "id": "15653", "js_event_callbacks": {}, "js_property_callbacks": {}, "name": null, "subscribed_events": [], "tags": [] }
Range1d
A fixed, closed range [start, end] in a continuous scalar dimension.
In addition to supplying start and end keyword arguments to the Range1d initializer, you can also instantiate with the convenience syntax:
Range(0, 10) # equivalent to Range(start=0, end=10)
If set to 'auto', the bounds will be computed to the start and end of the Range.
'auto'
By default, bounds are None and your plot to pan/zoom as far as you want. If you only want to constrain one end of the plot, you can set min or max to None.
Examples:
Range1d(0, 1, bounds='auto') # Auto-bounded to 0 and 1 (Default behavior) Range1d(start=0, end=1, bounds=(0, None)) # Maximum is unbounded, minimum bounded to 0
The end of the range.
The level that the range is allowed to zoom out, expressed as the maximum visible interval. Can be a TimeDelta. Note that bounds can impose an implicit constraint on the maximum interval as well.
The level that the range is allowed to zoom in, expressed as the minimum visible interval. If set to None (default), the minimum interval is not bound. Can be a TimeDelta.
reset_end
The end of the range to apply when resetting. If set to None defaults to the end value during initialization.
reset_start
The start of the range to apply after reset. If set to None defaults to the start value during initialization.
The start of the range.
{ "bounds": null, "end": 1, "id": "15659", "js_event_callbacks": {}, "js_property_callbacks": {}, "max_interval": null, "min_interval": null, "name": null, "reset_end": null, "reset_start": null, "start": 0, "subscribed_events": [], "tags": [] }