带 Altair 的半圆甜甜圈图

Semi Circle Donut Chart with Altair

我是 Altair 的新手。你能帮我弄清楚如何在 Python 中绘制这样的东西吗?

我认为目前不可能将每个类别的着色与一半 pie/donut 图表结合起来。你可以把它和一个完整的图表结合起来,或者有一个单一颜色的半个图表:

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]})

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

pie + pie.mark_text(radius=170, fontSize=16).encode(text='category')

from math import pi

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=75, theta=pi/2, theta2=-pi/2)

这似乎对我有用。

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]})

pie = alt.Chart(source).mark_arc(innerRadius=75).encode(
    theta=alt.Theta(field="value", type="quantitative", stack=True, scale=alt.Scale(type="linear",rangeMax=1.5708, rangeMin=-1.5708 )),
    color=alt.Color(field="category", type="nominal"),
)

pie + pie.mark_text(radius=170, fontSize=16).encode(text='category')