Search code examples
altairvega-lite

Semi Circle Donut Chart with Altair


I'm new to Altair. Could you help me to figure out how to plot something like this in Python?

enter image description here


Solution

  • This seems to work for me.

    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')
    

    enter image description here