Interactivity Options#

Note

These options only apply to the interactive plotting backends (e.g. Bokeh), not to the static backend Matplotlib.

Bokeh specific options for adding hover tools as well as other interactive tools like tap tool and box select tool:

Parameters

Description

hover (bool or str or None, default=None)

Whether to show hover tooltips, default is True unless datashade=True in which case hover is False by default. Also accepts 'hline' and 'vline' to change the hit-testing mode.

hover_cols (list or str, default=[])

Additional columns to add to the hover tool or ‘all’ which will include all columns (including indexes if use_index=True).

hover_formatters (dict or None, default=None)

A dict of formatting options for the hover tooltip.

Deprecated since version 0.12: Use hover_tooltips instead.

hover_tooltips (list[str] or list[tuple] or None, default=None)

A list of dimensions to be displayed in the hover tooltip.

toolbar (str or bool or None, optional)

Whether to display a toolbar and where to place it. Displayed by default, disabled with 'disable', None or False. Location must be one 'above', 'below', 'left', or 'right' (the default).

autohide_toolbar (bool, optional)

Whether to automatically hide the toolbar until the user hovers over the plot. This keyword has no effect if the toolbar is disabled (toolbar=None). Default is False.

tools (list, default=[])

List of tool instances or strings (e.g. [‘tap’, ‘box_select’])

hover#

Enables or disables hover tooltips on the plot, also accepts 'hline' and 'vline' to change the hit-testing mode.

Note

This option is True by default for most plots, but is automatically set to False when datashade=True and selector is not set, since no relevant data can be displayed as HoloViews returns to the front-end an RGB element that doesn’t include the aggregated data. If you’re using datashade=True and still want interactivity, consider alternatives like using rasterize=True, combining datashade with dynspread, or enabling resample_when.

Note

  • errorbars plots: Hover is always disabled because Bokeh’s annotation glyphs (used for error bars) don’t support hover interaction.

import hvplot.pandas  # noqa

df = hvplot.sampledata.penguins("pandas")

opts = dict(
    x='bill_length_mm', y='bill_depth_mm',
    by='species', frame_width=250,
)
plot1 = df.hvplot.scatter(title='Scatter with hover tool (Default)', **opts)
plot2 = df.hvplot.scatter(hover=False, title='Scatter without hover tool', **opts)
plot1 + plot2

Particularly useful for time series plots, hover='vline' displays tooltips with data collected from points that intersect vertically with the cursor.

import hvplot.pandas  # noqa

df = hvplot.sampledata.stocks("pandas").set_index("date")["Apple"]

df.hvplot.line(hover="vline", title="hover with vline mode")

hover_cols#

Specifies additional columns from the dataset to be shown in the hover tooltip.

  • Accepts a list of column names, a single column name as a string, or ‘all’ to include all available columns.

  • When set to ‘all’, it includes index columns only if use_index=True.

Note

hover_cols complements the default dimensions shown in the tooltip but does not override them.

import hvplot.pandas  # noqa

df = hvplot.sampledata.penguins("pandas")

opts = dict(
    x='bill_length_mm', y='bill_depth_mm',
    by='species', frame_width=250,
)
plot1 = df.hvplot.scatter(title='Default hover_cols', **opts)
plot2 = df.hvplot.scatter(
    hover_cols=['sex', 'body_mass_g'], title='Additional hover columns', **opts
)
plot3 = df.hvplot.scatter(
    hover_cols='all', title='All hover columns', **opts
)

plot4 = df.hvplot.scatter(
    hover_cols='all',
    use_index=False,
    title='All hover columns without index',
    **opts
)
(plot1 + plot2 + plot3 + plot4).cols(2)

Hover on the points in each of the examples to see the displayed hover information.

hover_tooltips#

Controls the contents and layout of the hover tooltip using a list of tooltips. Each tooltip is a 2-tuple like ("label", "@<column_name>") used for specifying the name and format of the hover tooltip.

Formatting options in the tooltips can be one of:

  • numeral format – for abbreviated numbers (e.g. 1k, 3.2M)

  • datetime format – for date/time values

  • printf format – for precision control like “%.2f”

If set, it overrides the default auto-generated tooltips.

Tip

Be sure to use @-prefixed dimension names inside each tooltip for the dimension names.

import hvplot.pandas  # noqa

df = hvplot.sampledata.stocks("pandas")

opts = dict(
    x='date', frame_width=250,
    group_label="Company" # rename group label
)
plot1 = df.hvplot.line(**opts, title="Default hover tooltips")
plot2 = df.hvplot.line(
    hover_tooltips=[
        ("Company", "@Company"), # No formatting
        ("Date", "@date{%b %Y}"), # datetime format to Month Year style
        ("Price", "@value{$0.0f}"), # printf format to 2 decimal
    ],
    title="Customized hover tooltips",
    **opts
)
plot1 + plot2

See also

See bokeh formatters for more information about formatting the tooltips.

toolbar#

This option controls whether the toolbar should be displayed and its location.

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({"y": [1, 4, 2]})

df.hvplot.scatter(toolbar="right", title="toolbar=right (default)", height=250, width=400)
df.hvplot.scatter(toolbar="left", title="toolbar=left", height=250, width=400)
df.hvplot.scatter(toolbar="above", title="toolbar=above", height=150, width=400)
df.hvplot.scatter(toolbar="below", title="toolbar=below", height=150, width=400)
df.hvplot.scatter(toolbar=None, title="toolbar=None", height=150, width=400)

In a layout, a unique toolbar is displayed above.

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({"y": [1, 4, 2]})

df.hvplot.scatter(width=300, height=150) + df.hvplot.line(width=300, height=150)

To control the toolbar, call .opts(toolbar=...) on the layout object with one of 'above', 'below', 'left', 'right', or 'None' (to disable it).

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({"y": [1, 4, 2]})

layout = df.hvplot.scatter(width=300, height=150) + df.hvplot.line(width=300, height=150)
layout.opts(toolbar="below")

autohide_toolbar#

By default the Bokeh toolbar is always displayed. This option allows to automatically hide the toolbar when the plot is not hovered.

import hvplot.pandas  # noqa
import pandas as pd

df = pd.DataFrame({"y": [1, 4, 2]})

df.hvplot.scatter(autohide_toolbar=True)

In order to enable this option globally, add this snippet to your code:

import holoviews as hv

hv.plotting.bokeh.plot.BokehPlot.autohide_toolbar = True

tools#

A list of interactive tools to enable on the plot. These are Bokeh tool names or tool instances (e.g., tap, box_select, or HoverTool()).

Tools typically appear as a vertical toolbar on the right-hand side of the plot. Common options include:

  • hover – show tooltips

  • tap – click to select points

  • box_select, lasso_select – select a region

  • wheel_zoom, pan, reset – for navigation

The hover tool is automatically added by default when not already in tools.

import hvplot.pandas  # noqa

df = hvplot.sampledata.penguins("pandas")

df.hvplot.scatter(
    x='bill_length_mm', y='bill_depth_mm',
    tools=['tap', 'lasso_select'],
    title='Interactive plot with additional tools'
)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.