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