Reputation: 345
I noticed the Vega-Lite 3.0.0 release notes mentioned "Tooltips are included by default," and this is true for boxplots in Altair 3.0, but not for other plots like histograms.
When I open my Altair plots in the Vega Editor, I see "mark": {"tooltip": null}}
in the config
section at the top of the chart definition. If I remove "mark": {"tooltip": null}
, tooltips work automatically.
So, instead of this:
{
"config": {"view": {"width": 400, "height": 300}, "mark": {"tooltip": null}},
"data": {
"url": "https://vega.github.io/vega-datasets/data/seattle-temps.csv"
},
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "temp"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v3.2.1.json"
}
I would like the Altair output to be like this:
{
"config": {"view": {"width": 400, "height": 300}},
"data": {
"url": "https://vega.github.io/vega-datasets/data/seattle-temps.csv"
},
"mark": "bar",
"encoding": {
"x": {"type": "quantitative", "bin": true, "field": "temp"},
"y": {"type": "quantitative", "aggregate": "count"}
},
"$schema": "https://vega.github.io/schema/vega-lite/v3.2.1.json"
}
Is there a way to prevent Altair from disabling tooltips?
Upvotes: 1
Views: 772
Reputation: 86320
We made the choice to disable automatic tooltips because Vega-Lite will disable them in the near future. If you would like to enable default tooltips in a particular chart, you can use, e.g.
alt.Chart(data).mark_point(tooltip=alt.TooltipContent('encoding'))
or
chart.configure_mark(tooltip=alt.TooltipContent('encoding'))
If you want every chart in your session to include that setting, you can create an altair theme that enables this by default. For example:
def tooltips():
return {'config': {'mark': {'tooltip': {'content': 'encoding'}}}}
alt.themes.register('tooltips', tooltips)
alt.themes.enable('tooltips')
Upvotes: 5