Deactivate tooltip in Altair

Viewed 195

I am looking at this example of a bar chart with error bars in Altair with Python. If one hovers over the errorbars one gets information about properties of the data. However, I'd like to deactivate this. How can I do this? The code is this one:

import altair as alt
from vega_datasets import data

source = data.barley()

bars = alt.Chart().mark_bar().encode(
    x='year:O',
    y=alt.Y('mean(yield):Q', title='Mean Yield'),
    color='year:N',
)

error_bars = alt.Chart().mark_errorbar(extent='ci').encode(
    x='year:O',
    y='yield:Q'
)

alt.layer(bars, error_bars, data=source).facet(
    column='site:N'
)
1 Answers

You can override the default tooltip using the tooltip encoding channel. If you want no tooltip, you can set it to alt.value(None):

error_bars = alt.Chart().mark_errorbar(extent='ci').encode(
    x='year:O',
    y='yield:Q',
    tooltip=alt.value(None),
)

It's a bit unfortunate that mark_errorbar does not support the tooltip=None argument, as other mark types do; that would feel more natural I think.

Related