Altair: using the tooltip to read data values is hard in a jupyter notebook

Created on 27 Nov 2019  路  2Comments  路  Source: altair-viz/altair

Hello,
I love using altair for interactive data visualization. However i often struggle to have the tooltip display the values if the mouse isn't pointing exactly where altair expects it.
I haven't had this issue with similar libs (plotly for instance) : if you're pointing in the vicinity of the value you want to display, it works out just fine.
Not so much with altair in my experience, especially with lineplots. I've tried this with Opera and Chrome on a MacOS.
Here's the code snippet I'm using (df is some dataframe and TS is a Timestamp) :

library(altair)
alt.Chart(df).mark_line().encode(
    x='TS',
    y='N_BKGS',
    tooltip=['TS', 'N_BKGS']
).properties(width=800, height=600).interactive()

I'm using altair 3.2.0 and python 3.7.2

question vega-lite-related

Most helpful comment

Tooltips don't work well for line markings. I usually work around this by adding a transparent layer with the tooltip; for example:

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.stocks.url).mark_line().encode(
    x='date:T',
    y='price:Q',
    color='symbol:N',
)

chart + chart.mark_point(size=100, opacity=0, tooltip=alt.TooltipContent("data"))

If you think the default behavior of the tooltip should be different, that would be worth a feature request in http://github.com/vega/vega-lite. Rendering details like this are not controlled by the Altair package.

All 2 comments

Tooltips don't work well for line markings. I usually work around this by adding a transparent layer with the tooltip; for example:

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.stocks.url).mark_line().encode(
    x='date:T',
    y='price:Q',
    color='symbol:N',
)

chart + chart.mark_point(size=100, opacity=0, tooltip=alt.TooltipContent("data"))

If you think the default behavior of the tooltip should be different, that would be worth a feature request in http://github.com/vega/vega-lite. Rendering details like this are not controlled by the Altair package.

Thanks for the tip !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bmcfee picture bmcfee  路  3Comments

floringogianu picture floringogianu  路  3Comments

dzonimn picture dzonimn  路  3Comments

tonylee3399 picture tonylee3399  路  3Comments

breadbaron picture breadbaron  路  4Comments