甜甜圈图#

这个例子展示了如何使用 mark_arc 制作一个甜甜圈图。 这是从一个相应的 Vega-Lite 示例中改编而来: Donut Chart

import pandas as pd
import altair as alt

source = pd.DataFrame({
    "category": [1, 2, 3, 4, 5, 6],
    "value": [4, 6, 10, 3, 7, 8]
})

alt.Chart(source).mark_arc(innerRadius=50).encode(
    theta="value",
    color="category:N",
)
import pandas as pd
import altair as alt

source = pd.DataFrame({"category": [1, 2, 3, 4, 5, 6], "value": [4, 6, 10, 3, 7, 8]})

alt.Chart(source).mark_arc(innerRadius=50).encode(
    theta=alt.Theta(field="value", type="quantitative"),
    color=alt.Color(field="category", type="nominal"),
)