bokeh.models.tools

Bokeh comes with a number of interactive tools.

There are five types of tool interactions:

  • Pan/Drag
  • Click/Tap
  • Scroll/Pinch
  • Actions
  • Inspectors

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 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 BoxSelectTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: box_select_icon

The box selection tool allows users to make selections on a Plot by indicating a rectangular 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 & Unselected Glyphs for information on styling selected and unselected glyphs.

callback

property type: Instance(Callback)

A callback to run in the browser on completion of drawing a selection box. The cb_data parameter that is available to the Callback code will contain one BoxSelectTool-specific field:

Geometry:object containing the coordinates of the selection box
dimensions

property type: List(Enum(‘width’, ‘height’, ‘x’, ‘y’))

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 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.

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.

renderers

property type: List(Instance(Renderer))

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

select_every_mousemove

property type: Bool

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

[
  {
    "attributes": {
      "callback": null,
      "dimensions": [
        "width",
        "height"
      ],
      "doc": null,
      "id": "b88ed23a-6860-4f2c-8b93-54a4c60a951d",
      "name": null,
      "names": [],
      "plot": null,
      "renderers": [],
      "select_every_mousemove": true,
      "tags": []
    },
    "id": "b88ed23a-6860-4f2c-8b93-54a4c60a951d",
    "type": "BoxSelectTool"
  }
]
class BoxSelectionOverlay(**kwargs)

Bases: bokeh.models.renderers.Renderer

An overlay renderer that Tool objects can use to render a ‘rubber band’ selection box on a Plot.

tool

property type: Instance(Tool)

The tool that this overlay should respond to.

[
  {
    "attributes": {
      "doc": null,
      "id": "b8684839-88af-4e5a-8037-b7b7a50dd01e",
      "name": null,
      "tags": [],
      "tool": null
    },
    "id": "b8684839-88af-4e5a-8037-b7b7a50dd01e",
    "type": "BoxSelection"
  }
]
class BoxZoomTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: box_zoom_icon

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.

dimensions

property type: List(Enum(‘width’, ‘height’, ‘x’, ‘y’))

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.

[
  {
    "attributes": {
      "dimensions": [
        "width",
        "height"
      ],
      "doc": null,
      "id": "29010ba9-06c2-4ae9-bf85-8aa176a301df",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "29010ba9-06c2-4ae9-bf85-8aa176a301df",
    "type": "BoxZoomTool"
  }
]
class CrosshairTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: inspector_icon

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 dimension property to only width or height.

dimensions

property type: List(Enum(‘width’, ‘height’, ‘x’, ‘y’))

Which dimensions the crosshair tool is to track. By default, both a vertical and horizontal line 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.

[
  {
    "attributes": {
      "dimensions": [
        "width",
        "height"
      ],
      "doc": null,
      "id": "6e6457ce-3d7a-419a-a972-d609a6d2423c",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "6e6457ce-3d7a-419a-a972-d609a6d2423c",
    "type": "CrosshairTool"
  }
]
class HelpTool(**kwargs)

Bases: bokeh.models.tools.Tool

The help tool is a widget designed to replace the hardcoded ‘Help’ link. The hover text can be customized through the help_tooltip attribute and the redirect site overridden as well.

help_tooltip

property type: String

Tooltip displayed when hovering over the help icon.

redirect

property type: String

Site to be redirected through upon click.

[
  {
    "attributes": {
      "doc": null,
      "help_tooltip": null,
      "id": "40845609-7aa5-4dc6-ab48-7a5bb3308810",
      "name": null,
      "plot": null,
      "redirect": null,
      "tags": []
    },
    "id": "40845609-7aa5-4dc6-ab48-7a5bb3308810",
    "type": "HelpTool"
  }
]
class HoverTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: inspector_icon

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 is to be displayed is configurable with the tooltips attribute 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"),
    ("foo", "@foo"),
    ("bar", "@bar"),
]

You can also supply a Callback to the HoverTool, to build custom interactions on hover. In this case you may want to turn the tooltips off by setting tooltips=None.

Warning

Hover tool does not currently work with the following glyphs:

  • annulus
  • arc
  • bezier
  • gear
  • image
  • image_rgba
  • image_url
  • multi_line
  • oval
  • patch
  • quadratic
  • ray
  • segment
  • text
always_active

property type: Bool

Whether the hover tool must be explicitly activated.

callback

property type: Instance(Callback)

A callback to run in the browser whenever the input’s value changes. The cb_data parameter that is available to the Callback code will contain two HoverTool specific fields:

Index:object containing the indices of the hovered points in the data source
Geometry:object containing the coordinates of the hover cursor
line_policy

property type: Enum(‘prev’, ‘next’, ‘nearest’, ‘interp’, ‘none’)

When showing tooltips for lines, whether the tooltip position should be the “previous” or “next” points on the line, the nearest point to the current mouse position, or interpolate along the line to the current mouse position.

mode

property type: Enum(‘mouse’, ‘hline’, ‘vline’)

Whether to consider hover pointer as a point (x/y values), or a span on h or v directions.

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.

point_policy

property type: Enum(‘snap_to_data’, ‘follow_mouse’, ‘none’)

Whether the tooltip position should snap to the “center” position of the associated glyph, or always follow the current mouse cursor position.

renderers

property type: List(Instance(Renderer))

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

tooltips

property type: Either(String, List(Tuple(String, String)))

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 selected point in the data source
$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), and ‘swatch’ to also display a small color swatch.

None is 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. dict or OrderedDict. However, if a dict is used, the visual presentation order is unpecified.

[
  {
    "attributes": {
      "always_active": true,
      "callback": null,
      "doc": null,
      "id": "665ee4a1-0dd2-45a1-b7ff-cf4b51e856eb",
      "line_policy": "prev",
      "mode": "mouse",
      "name": null,
      "names": [],
      "plot": null,
      "point_policy": "snap_to_data",
      "renderers": [],
      "tags": [],
      "tooltips": null
    },
    "id": "665ee4a1-0dd2-45a1-b7ff-cf4b51e856eb",
    "type": "HoverTool"
  }
]
class LassoSelectTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: lasso_select_icon

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 & 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 seletion that might exist.

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.

renderers

property type: List(Instance(Renderer))

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

select_every_mousemove

property type: Bool

Whether a selection computation should happen on every mouse event, or only once, when the selection region is completed.

[
  {
    "attributes": {
      "doc": null,
      "id": "e530d309-7431-4477-8de3-c6556b9972d2",
      "name": null,
      "names": [],
      "plot": null,
      "renderers": [],
      "select_every_mousemove": true,
      "tags": []
    },
    "id": "e530d309-7431-4477-8de3-c6556b9972d2",
    "type": "LassoSelectTool"
  }
]
class PanTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: pan_icon

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 the horizontal dimension kept fixed.

dimensions

property type: List(Enum(‘width’, ‘height’, ‘x’, ‘y’))

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.

[
  {
    "attributes": {
      "dimensions": [
        "width",
        "height"
      ],
      "doc": null,
      "id": "cdc110d4-7b77-46a1-b924-c4efb1d3f6fd",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "cdc110d4-7b77-46a1-b924-c4efb1d3f6fd",
    "type": "PanTool"
  }
]
class PolySelectTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: poly_select_icon

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 double click (or tap) indicates the selection region is ready.

See Selected & 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 seletion that might exist.

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.

renderers

property type: List(Instance(Renderer))

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

[
  {
    "attributes": {
      "doc": null,
      "id": "dc3771a5-35d4-4d92-8cca-fbbbb9fc765c",
      "name": null,
      "names": [],
      "plot": null,
      "renderers": [],
      "tags": []
    },
    "id": "dc3771a5-35d4-4d92-8cca-fbbbb9fc765c",
    "type": "PolySelectTool"
  }
]
class PreviewSaveTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: save_icon

The preview/save tool is an action. When activated in the toolbar, the tool presents a modal dialog with an image reproduction of the Plot, which may be saved as a png image by right clicking on the image.

Note

Work is ongoing to support headless (svg, png) image creation without requireing user interaction. See issue 538 to track progress or contribute.

[
  {
    "attributes": {
      "doc": null,
      "id": "da415420-5ff2-48b7-ab1e-d350e40ca8b9",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "da415420-5ff2-48b7-ab1e-d350e40ca8b9",
    "type": "PreviewSaveTool"
  }
]
class ResetTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: reset_icon

The reset tool is an action. When activated in teh toolbar, the tool resets the data bounds of the plot to their values when the plot was initially created.

Note

This tool does not also reset the plot canvas size, if the plot has been resized using the ResizeTool. That feature may be added in a future release.

[
  {
    "attributes": {
      "doc": null,
      "id": "69b7463c-c591-4b5e-aba5-904e0d8c4272",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "69b7463c-c591-4b5e-aba5-904e0d8c4272",
    "type": "ResetTool"
  }
]
class ResizeTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: resize_icon

The resize tool allows the user to left-drag a mouse or drag a finger to resize the entire plot area on the screen.

[
  {
    "attributes": {
      "doc": null,
      "id": "baa04477-accf-4f6d-acbd-89376516e8e8",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "baa04477-accf-4f6d-acbd-89376516e8e8",
    "type": "ResizeTool"
  }
]
class TapTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: tap_select_icon

The tap selection tool allows the user to select at single points by left-clicking a mouse, or tapping with a finger.

See Selected & 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 seletion that might exist.

always_active

property type: Bool

Whether the hover tool must be explicitly activated.

callback

property type: Instance(Callback)

A client-side action specification, like opening a URL, showing a dialog box, etc. See Action for details.

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.

renderers

property type: List(Instance(Renderer))

An explicit list of renderers to hit test again. If unset, defaults to all renderers on a plot.

[
  {
    "attributes": {
      "always_active": true,
      "callback": null,
      "doc": null,
      "id": "1f1d9ecf-9281-48d9-ab0c-1c0b93cc7664",
      "name": null,
      "names": [],
      "plot": null,
      "renderers": [],
      "tags": []
    },
    "id": "1f1d9ecf-9281-48d9-ab0c-1c0b93cc7664",
    "type": "TapTool"
  }
]
class Tool(**kwargs)

Bases: bokeh.plot_object.PlotObject

A base class for all interactive tool types. Tool is not generally useful to instantiate on its own.

plot

property type: Instance(Plot)

The Plot that this tool will act on.

[
  {
    "attributes": {
      "doc": null,
      "id": "aa98c3c9-5081-44a2-8402-208fa151dc65",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "aa98c3c9-5081-44a2-8402-208fa151dc65",
    "type": "Tool"
  }
]
class ToolEvents(**kwargs)

Bases: bokeh.plot_object.PlotObject

geometries

property type: List(Dict(String, Any))

[
  {
    "attributes": {
      "doc": null,
      "geometries": [],
      "id": "218abd93-e77f-498b-bda1-8eec40dd289e",
      "name": null,
      "tags": []
    },
    "id": "218abd93-e77f-498b-bda1-8eec40dd289e",
    "type": "ToolEvents"
  }
]
class WheelZoomTool(**kwargs)

Bases: bokeh.models.tools.Tool

toolbar icon: wheel_zoom_icon

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

property type: List(Enum(‘width’, ‘height’, ‘x’, ‘y’))

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.

[
  {
    "attributes": {
      "dimensions": [
        "width",
        "height"
      ],
      "doc": null,
      "id": "1eab58dc-559f-4b27-a99d-3162d3fd62a4",
      "name": null,
      "plot": null,
      "tags": []
    },
    "id": "1eab58dc-559f-4b27-a99d-3162d3fd62a4",
    "type": "WheelZoomTool"
  }
]