tools#
Bokeh comes with a number of interactive tools.
There are five types of tool interactions:
|
|
|
|
|
For the first three comprise the category of gesture tools, and only one tool for each gesture can be active at any given time. The active tool is indicated on the toolbar by a highlight next to the tool. Actions are immediate or modal operations that are only activated when their button in the toolbar is pressed. Inspectors are passive tools that merely report information or annotate the plot in some way, and may always be active regardless of what other tools are currently active.
- class ActionTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that are buttons in the toolbar.
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.
- class BoxEditTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
Allows drawing, dragging and deleting box-like glyphs (e.g.
Block,Rect,HStrip) on one or more renderers by editing the underlyingColumnDataSourcedata. Like other drawing tools, the renderers that are to be edited must be supplied explicitly as a list. When drawing a new box the data will always be added to theColumnDataSourceon the first supplied renderer.The tool will modify the columns on the data source corresponding to the
x,y,widthandheightvalues of the glyph. Any additional columns in the data source will be padded withempty_value, when adding a new box.The supported actions include:
Add box: Hold shift then click and drag anywhere on the plot or press once to start drawing, move the mouse and press again to finish drawing.
Move box: Click and drag an existing box, the box will be dropped once you let go of the mouse button.
Delete box: Tap a box to select it then press BACKSPACE key while the mouse is within the plot area.
To Move or Delete multiple boxes at once:
Move selection: Select box(es) with SHIFT+tap (or another selection tool) then drag anywhere on the plot. Selecting and then dragging on a specific box will move both.
Delete selection: Select box(es) with SHIFT+tap (or another selection tool) then press BACKSPACE while the mouse is within the plot area.
- dimensions#
Which dimensions the box drawing is to be free in. By default, users may freely draw boxes with any dimensions. If only “width” is set, the box will be constrained to span the entire vertical space of the plot, only the horizontal dimension can be controlled. If only “height” is set, the box will be constrained to span the entire horizontal space of the plot, and the vertical dimension can be controlled.
- num_objects#
Defines a limit on the number of boxes that can be drawn. By default there is no limit on the number of objects, but if enabled the oldest drawn box will be dropped to make space for the new box being added.
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class BoxSelectTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The box selection tool allows users to make selections on a Plot by showing a rectangular region by dragging the mouse or a finger over the plot area. The end of the drag event indicates the selection region is ready.
See Selected and unselected glyphs for information on styling selected and unselected glyphs.
- dimensions#
Which dimensions the box selection is to be free in. By default, users may freely draw selections boxes with any dimensions. If only “width” is set, the box will be constrained to span the entire vertical space of the plot, only the horizontal dimension can be controlled. If only “height” is set, the box will be constrained to span the entire horizontal space of the plot, and the vertical dimension can be controlled.
- origin#
Indicates whether the rectangular selection area should originate from a corner (top-left or bottom-right depending on direction) or the center of the box.
- overlay#
A shaded annotation drawn to indicate the selection region.
- class BoxZoomTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The box zoom tool allows users to define a rectangular region of a Plot to zoom to by dragging he mouse or a finger over the plot region. The end of the drag event indicates the selection region is ready.
Note
BoxZoomToolis incompatible withGMapPlotdue to the manner in which Google Maps exert explicit control over aspect ratios. Adding this tool to aGMapPlotwill have no effect.- dimensions#
Which dimensions the zoom box is to be free in. By default, users may freely draw zoom boxes with any dimensions. If only “width” is supplied, the box will be constrained to span the entire vertical space of the plot, only the horizontal dimension can be controlled. If only “height” is supplied, the box will be constrained to span the entire horizontal space of the plot, and the vertical dimension can be controlled.
- match_aspect#
Whether the box zoom region should be restricted to have the same aspect ratio as the plot region.
Note
If the tool is restricted to one dimension, this value has no effect.
- origin#
Indicates whether the rectangular zoom area should originate from a corner (top-left or bottom-right depending on direction) or the center of the box.
- overlay#
A shaded annotation drawn to indicate the selection region.
- class ClickPanTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A tool that allows to pan a plot by a fixed amount by clicking a button.
- direction#
The direction in which to pan the plot.
Accepted values are
"left","right","up"or"down", or their respective aliases"west","east","north","south".
- factor#
Percentage of the range to pan for each usage of the tool.
- class CopyTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The copy tool is an action tool, that allows copying the rendered contents of a plot or a collection of plots to system’s clipboard. This tools is browser dependent and may not function in certain browsers, or require additional permissions to be granted to the web page.
- class CrosshairTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The crosshair tool is a passive inspector tool. It is generally on at all times, but can be configured in the inspector’s menu associated with the toolbar icon shown above.
The crosshair tool draws a crosshair annotation over the plot, centered on the current mouse position. The crosshair tool may be configured to draw across only one dimension by setting the
dimensionproperty to onlywidthorheight.- dimensions#
Which dimensions the crosshair tool is to track. By default, both vertical and horizontal lines will be drawn. If only “width” is supplied, only a horizontal line will be drawn. If only “height” is supplied, only a vertical line will be drawn.
- line_alpha#
An alpha value to use to stroke paths with.
Acceptable values are floating-point numbers between 0 and 1 (0 being transparent and 1 being opaque).
- line_color#
A color to use to stroke paths with.
Acceptable values are:
any of the named CSS colors, e.g
'green','indigo'RGB(A) hex strings, e.g.,
'#FF0000','#44444444'CSS4 color strings, e.g.,
'rgba(255, 0, 127, 0.6)','rgb(0 127 0 / 1.0)', or'hsl(60deg 100% 50% / 1.0)'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 and 255, and a is between 0 and 1
a 32-bit unsigned integer using the 0xRRGGBBAA byte order pattern
- line_width#
Stroke width in units of pixels.
- overlay#
An annotation drawn to indicate the crosshair.
If
"auto", this will create spans depending on thedimensionsproperty, which based on its value, will result in either one span (horizontal or vertical) or two spans (horizontal and vertical).Alternatively the user can provide one
Spaninstance, where the dimension is indicated by thedimensionproperty of theSpan. Also twoSpaninstances can be provided. Providing explicitSpaninstances allows for constructing linked crosshair, when those instances are shared between crosshair tools of different plots.Note
This property is experimental and may change at any point. In particular in future this will allow using other annotations than
Spanand annotation groups.
- class CustomAction(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Execute a custom action, e.g.
CustomJScallback when a toolbar icon is activated.Example
tool = CustomAction(icon="icon.png", callback=CustomJS(code='alert("foo")')) plot.add_tools(tool)
- active#
If
True, the tool is currently engaged for its activity.
- active_callback#
A callback that allows to determine the state of the tool.
This callback is used to establish the initial and any subsequent state of the tool. it must return a boolean value. A value of any other type will be disregarded.
If
"auto"value is used, then any click of the button will toggle state. The initial state can be provided usingactiveproperty.If
Nonevalue is used, then the tool isn’t stateful.Note
This property is experimental and may change at any point.
- callback#
A Bokeh callback to execute when the custom action icon is activated.
This callback can return a boolean value to indicate the state of the tool. This is only applicable if
active_callbackisNone.
- disabled#
If
True, users can’t interact with the tool in any way.
- class CustomJSHover(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Define a custom formatter to apply to a hover tool field.
This model can be configured with JavaScript code to format hover tooltips. The JavaScript code has access to the current value to format, some special variables, and any format configured on the tooltip. The variable
valuewill contain the untransformed value. The variablespecial_varswill provide a dict with the following contents:xdata-space x-coordinate of the mouseydata-space y-coordinate of the mousesxscreen-space x-coordinate of the mousesyscreen-space y-coordinate of the mousedata_xdata-space x-coordinate of the hovered glyphdata_ydata-space y-coordinate of the hovered glyphindicescolumn indices of all currently hovered glyphsnamevalue of thenameproperty of the hovered glyph renderer
If the hover is over a “multi” glyph such as
PatchesorMultiLinethen asegment_indexkey will also be present.Finally, the value of the format passed in the tooltip specification is available as the
formatvariable.Example
As an example, the following code adds a custom formatter to format WebMercator northing coordinates (in meters) as a latitude:
lat_custom = CustomJSHover(code=""" const projections = Bokeh.require("core/util/projections"); const x = special_vars.x const y = special_vars.y const coords = projections.wgs84_mercator.invert(x, y) return "" + coords[1] """) p.add_tools(HoverTool( tooltips=[( 'lat','@y{custom}' )], formatters={'@y':lat_custom} ))
Warning
The explicit purpose of this Bokeh Model is to embed raw JavaScript code for a browser to execute. If any part of the code is derived from untrusted user inputs, then you must take appropriate care to sanitize the user input prior to passing to Bokeh.
- args#
A mapping of names to Bokeh plot objects. These objects are made available to the callback code snippet as the values of named parameters to the callback.
- code#
A snippet of JavaScript code to transform a single value. The variable
valuewill contain the untransformed value and can be expected to be present in the function namespace at render time. Additionally, the variablespecial_varswill be available, and will provide a dict with the following contents:xdata-space x-coordinate of the mouseydata-space y-coordinate of the mousesxscreen-space x-coordinate of the mousesyscreen-space y-coordinate of the mousedata_xdata-space x-coordinate of the hovered glyphdata_ydata-space y-coordinate of the hovered glyphindicescolumn indices of all currently hovered glyphs
If the hover is over a “multi” glyph such as
PatchesorMultiLinethen asegment_indexkey will also be present.Finally, the value of the format passed in the tooltip specification is available as the
formatvariable.The snippet will be made into the body of a function and therefore requires a return statement.
Example
code = ''' return value + " total" '''
- class Drag(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that respond to drag events.
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.
- class EditTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for all interactive draw tool 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.
- default_overrides#
Padding values overriding
ColumnarDataSource.default_values.Defines values to insert into non-coordinate columns when a new glyph is inserted into the
ColumnDataSourcecolumns, e.g. when a circle glyph defines"x","y"and"color"columns, adding a new point will add the x and y-coordinates to"x"and"y"columns and the color column will be filled with the defined default value.
- empty_value#
The “last resort” padding value.
This is used the same as
default_values, when the tool was unable to figure out a default value otherwise. The tool will try the following alternatives in order:EditTool.default_overridesColumnarDataSource.default_valuesColumnarDataSource’s inferred default valuesEditTool.empty_value
- class ExamineTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A tool that allows to inspect and configure a model.
- class FreehandDrawTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
Allows freehand drawing of
PatchesandMultiLineglyphs. The glyph to draw may be defined via therenderersproperty.The tool will modify the columns on the data source corresponding to the
xsandysvalues of the glyph. Any additional columns in the data source will be padded with the declaredempty_value, when adding a new point.The supported actions include:
Draw vertices: Click and drag to draw a line
Delete patch/multi-line: Tap a patch/multi-line to select it then press BACKSPACE key while the mouse is within the plot area.
- num_objects#
Defines a limit on the number of patches or multi-lines that can be drawn. By default there is no limit on the number of objects, but if enabled the oldest drawn patch or multi-line will be overwritten when the limit is reached.
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class FullscreenTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A tool that allows to enlarge a UI element to fullscreen.
- class GestureTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that respond to drag events.
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.
- class HelpTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A button tool to provide a “help” link to users.
The hover text can be customized through the
help_tooltipattribute and the redirect site overridden as well.- redirect#
Site to be redirected through upon click.
- class HoverTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The hover tool is a passive inspector tool. It is generally on at all times, but can be configured in the inspector’s menu associated with the toolbar icon shown above.
By default, the hover tool displays informational tooltips whenever the cursor is directly over a glyph. The data to show comes from the glyph’s data source, and what to display is configurable with the
tooltipsproperty that maps display names to columns in the data source, or to special known variables.Here is an example of how to configure and use the hover tool:
# Add tooltip (name, field) pairs to the tool. See below for a # description of possible field values. hover.tooltips = [ ("index", "$index"), ("(x,y)", "($x, $y)"), ("radius", "@radius"), ("fill color", "$color[hex, swatch]:fill_color"), ("fill color", "$color[hex]:fill_color"), ("fill color", "$color:fill_color"), ("fill color", "$swatch:fill_color"), ("foo", "@foo"), ("bar", "@bar"), ("baz", "@baz{safe}"), ("total", "@total{$0,0.00}"), ]
You can also supply a
Callbackto theHoverTool, to build custom interactions on hover. In this case you may want to turn the tooltips off by settingtooltips=None.Warning
When supplying a callback or custom template, the explicit intent of this Bokeh Model is to embed raw HTML and JavaScript code for a browser to execute. If any part of the code is derived from untrusted user inputs, then you must take appropriate care to sanitize the user input prior to passing to Bokeh.
Hover tool does not currently work with the following glyphs:
annulus
arc
bezier
image_url
oval
patch
quadratic
ray
step
text
- anchor#
If point policy is set to “snap_to_data”, anchor defines the attachment point of a tooltip. The default is to attach to the center of a glyph.
- attachment#
Whether the tooltip should be displayed to the left or right of the cursor position or above or below it, or if it should be automatically placed in the horizontal or vertical dimension.
- callback#
A callback to run in the browser whenever the input’s value changes. The
cb_dataparameter that is available to the Callback code will contain twoHoverToolspecific fields:- Index:
object containing the indices of the hovered points in the data source
- Geometry:
object containing the coordinates of the hover cursor
- filters#
Allows filtering hover results using a
CustomJScallback.An example of a simple filter function: .. code:
filter = ''' export default (args, tool, {value: x, row, index, field, data_source, vars}) => { return x >= 0 } ''' HoverTool(filters={"@x": CustomJS(args={}, code=filter)})
- formatters#
Specify the formatting scheme for data source columns, e.g.
tool.formatters = {"@date": "datetime"}
will cause format specifications for the “date” column to be interpreted according to the “datetime” formatting scheme. The following schemes are available:
- “numeral”:
Provides a wide variety of formats for numbers, currency, bytes, times, and percentages. The full set of formats can be found in the
NumeralTickFormatterreference documentation.- “datetime”:
Provides formats for date and time values. The full set of formats is listed in the
DatetimeTickFormatterreference documentation.- “printf”:
Provides formats similar to C-style “printf” type specifiers. See the
PrintfTickFormatterreference documentation for complete details.
If no formatter is specified for a column name, the default
"numeral"formatter is assumed.
- limit#
Limit the number the number of data points for which tooltips will be showed.
By default
HoverToolwill show tooltips for all hit data points.
- line_policy#
Specifies where the tooltip will be positioned when hovering over line glyphs:
- “prev”:
between the nearest two adjacent line points, positions the tooltip at the point with the lower (“previous”) index
- “next”:
between the nearest two adjacent line points, positions the tooltip at the point with the higher (“next”) index
- “nearest”:
between the nearest two adjacent line points, positions the tooltip on the point that is nearest to the mouse cursor location
- “interp”:
positions the tooltip at an interpolated point on the segment joining the two nearest adjacent line points.
- “none”:
positions the tooltip directly under the mouse cursor location
- mode#
Whether to consider hover pointer as a point (x/y values), or a span on h or v directions.
- muted_policy#
Whether to avoid showing tooltips on muted glyphs.
- point_policy#
Whether the tooltip position should snap to the “center” (or other anchor) position of the associated glyph, or always follow the current mouse cursor position.
- renderers#
A list of renderers to hit test against. If unset, defaults to all renderers on a plot.
- show_arrow#
Whether tooltip’s arrow should be shown.
- sort_by#
Allows sorting hover results by a field or a sequence of fields.
Additionally sort direction can be provided when using the sequence form, even if providing a single field. The default sort order is based on data index and/or proximity to the hit point.
- tooltips#
The (name, field) pairs describing what the hover tool should display when there is a hit.
Field names starting with “@” are interpreted as columns on the data source. For instance, “@temp” would look up values to display from the “temp” column of the data source.
Field names starting with “$” are special, known fields:
- $index:
index of hovered point in the data source
- $name:
value of the
nameproperty of the hovered glyph renderer- $x:
x-coordinate under the cursor in data space
- $y:
y-coordinate under the cursor in data space
- $sx:
x-coordinate under the cursor in screen (canvas) space
- $sy:
y-coordinate under the cursor in screen (canvas) space
- $color:
color data from data source, with the syntax:
$color[options]:field_name. The available options are:hex(to display the color as a hex value),swatch(color data from data source displayed as a small color box)- $swatch:
color data from data source displayed as a small color box
Field names that begin with
@are associated with columns in aColumnDataSource. For instance the field name"@price"will display values from the"price"column whenever a hover is triggered. If the hover is for the 17th glyph, then the hover tooltip will correspondingly display the 17th price value.Note that if a column name contains spaces, the it must be supplied by surrounding it in curly braces, e.g.
@{adjusted close}will display values from a column named"adjusted close".Sometimes (especially with stacked charts) it is desirable to allow the name of the column be specified indirectly. The field name
@$nameis distinguished in that it will look up thenamefield on the hovered glyph renderer, and use that value as the column name. For instance, if a user hovers with the name"US East", then@$nameis equivalent to@{US East}.By default, values for fields (e.g.
@foo) are displayed in a basic numeric format. However it is possible to control the formatting of values more precisely. Fields can be modified by appending a format specified to the end in curly braces. Some examples are below."@foo{0,0.000}" # formats 10000.1234 as: 10,000.123 "@foo{(.00)}" # formats -10000.1234 as: (10000.123) "@foo{($ 0.00 a)}" # formats 1230974 as: $ 1.23 m
Specifying a format
{safe}after a field name will override automatic escaping of the tooltip data source. Any HTML tags in the data tags will be rendered as HTML in the resulting HoverTool output. See Custom tooltip for a more detailed example.Noneis also a valid value for tooltips. This turns off the rendering of tooltips. This is mostly useful when supplying other actions on hover via the callback property.Note
The tooltips attribute can also be configured with a mapping type, e.g.
dictorOrderedDict.
- class InspectTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that perform “inspections”, e.g.
HoverTool.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.
- toggleable#
This is a backwards compatibility alias for the ‘visible’ property.
Note
Property ‘toggleable’ was deprecated in Bokeh 3.4.0 and will be removed in the future. Update your code to use ‘visible’ instead.
- class LassoSelectTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The lasso selection tool allows users to make selections on a Plot by indicating a free-drawn “lasso” region by dragging the mouse or a finger over the plot region. The end of the drag event indicates the selection region is ready.
See Selected and unselected glyphs for information on styling selected and unselected glyphs.
Note
Selections can be comprised of multiple regions, even those made by different selection tools. Hold down the SHIFT key while making a selection to append the new selection to any previous selection that might exist.
- overlay#
A shaded annotation drawn to indicate the selection region.
- class LineEditTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The LineEditTool allows editing the intersection points of one or more
Lineglyphs. Glyphs to be edited are defined via therenderersproperty and a renderer for the intersections is set via theintersection_rendererproperty (must render a point-like Glyph (a subclass ofXYGlyph).The tool will modify the columns on the data source corresponding to the
xandyvalues of the glyph. Any additional columns in the data source will be padded with the declaredempty_value, when adding a new point.The supported actions include:
Show intersections: press an existing line
Move point: Drag an existing point and let go of the mouse button to release it.
- dimensions#
Which dimensions this edit tool is constrained to act in. By default the line edit tool allows moving points in any dimension, but can be configured to only allow horizontal movement across the width of the plot, or vertical across the height of the plot.
- intersection_renderer#
The renderer used to render the intersections of a selected line
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class PanTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The pan tool allows the user to pan a Plot by left-dragging a mouse, or on touch devices by dragging a finger or stylus, across the plot region.
The pan tool also activates the border regions of a Plot for “single axis” panning. For instance, dragging in the vertical border or axis will effect a pan in the vertical direction only, with horizontal dimension kept fixed.
- dimensions#
Which dimensions the pan tool is constrained to act in. By default the pan tool will pan in any dimension, but can be configured to only pan horizontally across the width of the plot, or vertically across the height of the plot.
- class PointDrawTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The PointDrawTool allows adding, dragging and deleting point-like glyphs (i.e subclasses of
XYGlyph) on one or more renderers by editing the underlyingColumnDataSourcedata. Like other drawing tools, the renderers that are to be edited must be supplied explicitly as a list. Any newly added points will be inserted on theColumnDataSourceof the first supplied renderer.The tool will modify the columns on the data source corresponding to the
xandyvalues of the glyph. Any additional columns in the data source will be padded with the givenempty_valuewhen adding a new point.Note
The data source updates will trigger data change events continuously throughout the edit operations on the BokehJS side. In Bokeh server apps, the data source will only be synced once, when the edit operation finishes.
The supported actions include:
Add point: Tap anywhere on the plot
Move point: Tap and drag an existing point, the point will be dropped once you let go of the mouse button.
Delete point: Tap a point to select it then press BACKSPACE key while the mouse is within the plot area.
- add#
Enables adding of new points on tap events.
- drag#
Enables dragging of existing points on pan events.
- num_objects#
Defines a limit on the number of points that can be drawn. By default there is no limit on the number of objects, but if enabled the oldest drawn point will be dropped to make space for the new point.
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class PolyDrawTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The PolyDrawTool allows drawing, selecting and deleting
PatchesandMultiLineglyphs on one or more renderers by editing the underlyingColumnDataSourcedata. Like other drawing tools, the renderers that are to be edited must be supplied explicitly.The tool will modify the columns on the data source corresponding to the
xsandysvalues of the glyph. Any additional columns in the data source will be padded with the declaredempty_value, when adding a new point.If a
vertex_rendererwith an point-like glyph is supplied then thePolyDrawToolwill use it to display the vertices of the multi-lines or patches on all supplied renderers. This also enables the ability to snap to existing vertices while drawing.The supported actions include:
Add patch or multi-line: press to add the first vertex, then use tap to add each subsequent vertex, to finalize the draw action press to insert the final vertex or press the ESC key.
Move patch or multi-line: Tap and drag an existing patch/multi-line, the point will be dropped once you let go of the mouse button.
Delete patch or multi-line: Tap a patch/multi-line to select it then press BACKSPACE key while the mouse is within the plot area.
- drag#
Enables dragging of existing patches and multi-lines on pan events.
- num_objects#
Defines a limit on the number of patches or multi-lines that can be drawn. By default there is no limit on the number of objects, but if enabled the oldest drawn patch or multi-line will be dropped to make space for the new patch or multi-line.
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class PolyEditTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The PolyEditTool allows editing the vertices of one or more
PatchesorMultiLineglyphs. Glyphs to be edited are defined via therenderersproperty and a renderer for the vertices is set via thevertex_rendererproperty (must render a point-like Glyph (a subclass ofXYGlyph).The tool will modify the columns on the data source corresponding to the
xsandysvalues of the glyph. Any additional columns in the data source will be padded with the declaredempty_value, when adding a new point.The supported actions include:
Show vertices: press an existing patch or multi-line
Add vertex: press an existing vertex to select it, the tool will draw the next point, to add it tap in a new location. To finish editing and add a point press otherwise press the ESC key to cancel.
Move vertex: Drag an existing vertex and let go of the mouse button to release it.
Delete vertex: After selecting one or more vertices press BACKSPACE while the mouse cursor is within the plot area.
- renderers#
A list of renderers corresponding to glyphs that may be edited.
- class PolySelectTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The polygon selection tool allows users to make selections on a Plot by indicating a polygonal region with mouse clicks. single clicks (or taps) add successive points to the definition of the polygon, and a press click (or tap) indicates the selection region is ready.
See Selected and unselected glyphs for information on styling selected and unselected glyphs.
Note
Selections can be comprised of multiple regions, even those made by different selection tools. Hold down the SHIFT key while making a selection to append the new selection to any previous selection that might exist.
- overlay#
A shaded annotation drawn to indicate the selection region.
- class RangeTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The range tool allows the user to update range objects for either or both of the x- or y-dimensions by dragging a corresponding shaded annotation to move it or change its boundaries.
A common use case is to add this tool to a plot with a large fixed range, but to configure the tool range from a different plot. When the user manipulates the overlay, the range of the second plot will be updated automatically.
- overlay#
A shaded annotation drawn to indicate the configured ranges.
- start_gesture#
Which gesture will start a range update interaction in a new location.
When the value is
"pan", a new range starts at the location where a pointer drag operation begins. The range is updated continuously while the drag operation continues. Ending the drag operation sets the final value of the range.When the value is
"tap", a new range starts at the location where a single tap is made. The range is updated continuously while the pointer moves. Tapping at another location sets the final value of the range.When the value is
"none", only existing range definitions may be updated, by dragging their edges or interiors.Configuring this property allows to make this tool simultaneously co-exist with another tool that would otherwise share a gesture.
- x_interaction#
Whether to respond to horizontal pan motions when an
x_rangeis present.By default, when an
x_rangeis specified, it is possible to adjust the horizontal position of the range box by panning horizontally inside the box, or along the top or bottom edge of the box. To disable this, and fix the range box in place horizontally, set to False. (The box will still update if thex_rangeis updated programmatically.)
- x_range#
A range synchronized to the x-dimension of the overlay. If None, the overlay will span the entire x-dimension.
- y_interaction#
Whether to respond to vertical pan motions when a
y_rangeis present.By default, when a
y_rangeis specified, it is possible to adjust the vertical position of the range box by panning vertically inside the box, or along the top or bottom edge of the box. To disable this, and fix the range box in place vertically, set to False. (The box will still update if they_rangeis updated programmatically.)
- y_range#
A range synchronized to the y-dimension of the overlay. If None, the overlay will span the entire y-dimension.
- class RedoTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
Redo tool reverses the last action performed by undo tool.
- class ResetTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The reset tool is an action. When activated in the toolbar, the tool resets the data bounds of the plot to their values when the plot was initially created.
- class SaveTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The save tool is an action. When activated, the tool opens a download dialog which allows to save an image reproduction of the plot in PNG format. If automatic download is not support by a web browser, the tool falls back to opening the generated image in a new tab or window. User then can manually save it by right clicking on the image and choosing “Save As” (or similar) menu item.
- filename#
Optional string specifying the filename of the saved image (extension not needed). If a filename is not provided or set to None, the user is prompted for a filename at save time.
- class Scroll(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that respond to scroll events.
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.
- class Tap(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for tools that respond to tap/click events.
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.
- class TapTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The tap selection tool allows the user to select at single points by left-clicking a mouse, or tapping with a finger.
See Selected and unselected glyphs for information on styling selected and unselected glyphs.
Note
Selections can be comprised of multiple regions, even those made by different selection tools. Hold down the SHIFT key while making a selection to append the new selection to any previous selection that might exist.
- behavior#
This tool can be configured to either make selections or inspections on associated data sources. The difference is that selection changes propagate across bokeh and other components (e.g. selection glyph) will be notified. Inspections don’t act like this, so it’s useful to configure callback when setting behavior=’inspect’.
- callback#
A callback to execute whenever a glyph is “hit” by a mouse click or tap.
This is often useful with the
OpenURLmodel to open URLs based on a user clicking or tapping a specific glyph.However, it may also be a
CustomJSwhich can execute arbitrary JavaScript code in response to clicking or tapping glyphs. The callback will be executed for each individual glyph that is it hit by a click or tap, and will receive theTapToolmodel ascb_obj. The optionalcb_datawill have the data source as its.sourceattribute and the selection geometry as its.geometriesattribute.The
.geometriesattribute has 5 members..typeis the geometry type, which always a.pointfor a tap event..sxand.syare the screen X and Y coordinates where the tap occurred..xand.yare the converted data coordinates for the item that has been selected. The.xand.yvalues are based on the axis assigned to that glyph.Note
This callback does not execute on every tap, only when a glyph is “hit”. If you would like to execute a callback on every mouse tap, please see js_on_event callback triggers.
- gesture#
Specifies which kind of gesture will be used to trigger the tool, either a single or double tap.
- mode#
Defines what should happen when a new selection is made.
The default is to toggle the existing selection. Other options are to replace the selection, append to it, intersect with it, subtract from it or compute a symmetric difference with it.
- modifiers#
Allows to configure a combination of modifier keys, which need to be pressed during the selected gesture for this tool to trigger.
For example, to accept tap events only when
CtrlandShiftkeys are pressed, use:tool = TapTool(modifiers=dict(ctrl=True, shift=True)) plot.add_tools(tool)
or alternatively using a concise syntax:
tool = TapTool(modifiers="ctrl+shift") plot.add_tools(tool)
Warning
Configuring modifiers is a platform dependent feature and can make this tool unusable for example on mobile devices.
- class Tool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
A base class for all interactive tool 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.
- classmethod from_string(name: str) Tool[source]#
Takes a string and returns a corresponding Tool instance.
- description#
A string describing the purpose of this tool. If not defined, an auto-generated description will be used. This description will be typically presented in the user interface as a tooltip.
- group#
The name of the group this tool belongs to.
By default set to
True, indicating the default group. If set toFalse, it will prevent the tool from being grouped altogether (regardless ofToolbar.groupsetting).
- icon#
An icon to display in the toolbar.
The icon can provided as well known tool icon name, a CSS class selector, a data URI with an
image/*MIME, a path to an image, a PILImageobject, or an RGB(A) NumPy array. IfNone, then the intrinsic icon will be used (may depend on tool’s configuration).
- visible#
Whether a tool button associated with this tool should appear in the toolbar.
- class ToolMenu(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Toolbar represented in a menu or context menu form.
- toolbar#
Reference to a toolbar.
- class Toolbar(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Collect tools to display for a single plot.
- active_drag#
Specify a drag tool to be active when the plot is displayed.
- active_inspect#
Specify an inspection tool or sequence of inspection tools to be active when the plot is displayed.
- active_multi#
Specify an active multi-gesture tool, for instance an edit tool or a range tool.
Note that activating a multi-gesture tool will deactivate any other gesture tools as appropriate. For example, if a pan tool is set as the active drag, and this property is set to a
BoxEditToolinstance, the pan tool will be deactivated (i.e. the multi-gesture tool will take precedence).
- active_scroll#
Specify a scroll/pinch tool to be active when the plot is displayed.
- active_tap#
Specify a tap/click tool to be active when the plot is displayed.
- autohide#
False. If True, hides toolbar when cursor is not in canvas.
- Type:
Whether the toolbar will be hidden by default. Default
- group#
Whether to group common tools.
- group_types#
Only group tools of the given types.
- logo#
What version of the Bokeh logo to display on the toolbar. If set to None, no logo will be displayed.
- tools#
A list of tools to add to the plot.
- class UndoTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
Undo tool allows to restore previous state of the plot.
- class WheelPanTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The wheel pan tool allows the user to pan the plot along the configured dimension using the scroll wheel.
- dimension#
Which dimension the wheel pan tool is constrained to act in. By default the wheel pan tool will pan the plot along the x-axis.
- modifiers#
Allows to configure a combination of modifier keys, which need to be pressed during the selected gesture for this tool to trigger.
For example, to pan only when
CtrlandShiftkeys are pressed, use:tool = WheelPanTool(modifiers=dict(ctrl=True, shift=True)) plot.add_tools(tool)
or alternatively using a concise syntax:
tool = WheelPanTool(modifiers="ctrl+shift") plot.add_tools(tool)
Note
Setting modifiers allows this tool to be automatically activated, if
Toolbar.active_scrollis set to"auto".Warning
Configuring modifiers is a platform dependent feature and can make this tool unusable for example on mobile devices.
- class WheelZoomTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The wheel zoom tool will zoom the plot in and out, centered on the current mouse location.
The wheel zoom tool also activates the border regions of a Plot for “single axis” zooming. For instance, zooming in the vertical border or axis will effect a zoom in the vertical direction only, with the horizontal dimension kept fixed.
- dimensions#
Which dimensions the wheel zoom tool is constrained to act in. By default the wheel zoom tool will zoom in any dimension, but can be configured to only zoom horizontally across the width of the plot, or vertically across the height of the plot.
- hit_test#
Whether to zoom only those renderer that are being pointed at.
This setting only applies when zooming renderers that were configured with sub-coordinates, otherwise it has no effect.
If
True, thenhit_test_modeproperty defines how hit testing is performed andhit_test_behaviorallows to configure other aspects of this setup. See respective properties for details.Note
This property is experimental and may change at any point
- hit_test_behavior#
Allows to configure which renderers will be zoomed when
hit_testis enabled.By default (
hit_only) only actually hit renderers will be zoomed. An instance ofGroupBymodel can be used to tell what other renderers should be zoomed when a given one is hit.Note
This property is experimental and may change at any point
- hit_test_mode#
Allows to configure what geometry to use when
hit_testis enabled.Supported modes are
"point"for single point hit testing, andhlineandvlinefor either horizontal or vertical span hit testing.Note
This property is experimental and may change at any point
- level#
When working with composite scales (sub-coordinates), this property allows to configure which set of ranges to scale. The default is to scale top-level (frame) ranges.
- maintain_focus#
If True, then hitting a range bound in any one dimension will prevent all further zooming all dimensions. If False, zooming can continue independently in any dimension that has not yet reached its bounds, even if that causes overall focus or aspect ratio to change.
- modifiers#
Allows to configure a combination of modifier keys, which need to be pressed during the selected gesture for this tool to trigger.
For example, to zoom only when
CtrlandShiftkeys are pressed, use:tool = WheelZoomTool(modifiers=dict(ctrl=True, shift=True)) plot.add_tools(tool)
or alternatively using a concise syntax:
tool = WheelZoomTool(modifiers="ctrl+shift") plot.add_tools(tool)
Note
Setting modifiers allows this tool to be automatically activated, if
Toolbar.active_scrollis set to"auto".Warning
Configuring modifiers is a platform dependent feature and can make this tool unusable for example on mobile devices.
- renderers#
Restrict zoom to ranges used by the provided data renderers. If
"auto"then all ranges provided by the cartesian frame will be used.
- speed#
Speed at which the wheel zooms. Default is 1/600. Optimal range is between 0.001 and 0.09. High values will be clipped. Speed may very between browsers.
- zoom_on_axis#
Whether scrolling on an axis (outside the central plot area) should zoom that dimension. If enabled, the behavior of this feature can be configured with
zoom_togetherproperty.
- zoom_together#
Defines the behavior of the tool when zooming on an axis:
"none"zoom only the axis that’s being interacted with. Any cross axes nor any other axes in the dimension of this axis will be affected.
"cross"zoom the axis that’s being interacted with and its cross axis, if configured. No other axes in this or cross dimension will be affected.
"all"zoom all axes in the dimension of the axis that’s being interacted with. All cross axes will be unaffected.
- class ZoomInTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The zoom-in tool allows users to click a button to zoom in by a fixed amount.
- class ZoomOutTool(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
-
The zoom-out tool allows users to click a button to zoom out by a fixed amount.
- maintain_focus#
If
True, then hitting a range bound in any one dimension will prevent all further zooming in all dimensions. IfFalse, zooming can continue independently in any dimension that has not yet reached its bounds, even if that causes overall focus or aspect ratio to change.