Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

806 B
Raw Blame
_base = (
    alt.Chart([]) # <-- replace with data
    .transform_aggregate(count="count()", groupby=["bool_col"])
    .transform_joinaggregate(total="sum(count)")
    .transform_calculate(percentage="datum.count / datum.total")
    .encode(
        theta=alt.Theta(
            field="count",
            type="quantitative",
            stack=True,
        ),
        color=alt.Color("bool_col:N"),
        tooltip=[
            alt.Tooltip("bool_col:N", title="bool_col"),
            alt.Tooltip("count:Q", title="Number of records", format=",.0f"),
        ],
    )
)

_pie = _base.mark_arc(outerRadius=85)
_text = _base.mark_text(radius=110, size=13).encode(
    text=alt.Text("percentage:Q", format=".2%"),
)

_chart = (_pie + _text).properties(width="container").configure_view(stroke=None)
_chart