Answer a question

Is is possible to format the values within a tooltip for a boxplot? From this Vega documentation, it appears so, but I can't quite figure out how to do it with Altair for python

from vega_datasets import data

import altair as alt

source = data.population.url

alt.Chart(source).mark_boxplot().encode(
    alt.X("age:O"),
    alt.Y("people:Q"),
    tooltip=[
        alt.Tooltip("people:Q", format=",.2f"),
    ],
)

enter image description here

Answers

I believe you need to provide an aggregation for composite marks like mark_boxplot. This works:

from vega_datasets import data
import altair as alt

source = data.population.url

alt.Chart(source).mark_boxplot().encode(
    alt.X("age:O"),
    alt.Y("people:Q"),
    tooltip=alt.Tooltip("mean(people):Q", format=",.2f"),)

enter image description here

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐