import altair as alt
from vega_datasets import data
alt.__version__
'4.2.0rc1'
š Pie charts are now supported through the use of mark_arc
import pandas as pd
import altair as alt
source = pd.DataFrame({"values": [12, 23, 47, 6, 52, 19]})
base = alt.Chart(source).encode(
theta=alt.Theta("values:Q", stack=True),
radius=alt.Radius("values", scale=alt.Scale(type="sqrt", zero=True, rangeMin=20)),
color="values:N",
)
c1 = base.mark_arc(innerRadius=20, stroke="#fff")
c2 = base.mark_text(radiusOffset=10).encode(text="values:Q")
c1 + c2
šÆ Support for the datum encoding specifications
source = data.stocks()
lines = (
alt.Chart(source)
.mark_line()
.encode(x="date", y="price", color="symbol")
)
xrule = (
alt.Chart()
.mark_rule(strokeDash=[12, 6], size=2)
.encode(x=alt.datum(alt.DateTime(year=2006, month="November")))
)
yrule = (
alt.Chart().mark_rule(strokeDash=[12, 6], size=2).encode(y=alt.datum(350))
)
lines + yrule + xrule
š Angle encoding can now be used to control point styles
source = data.windvectors()
alt.Chart(source).mark_point(shape="wedge", filled=True).encode(
latitude="latitude",
longitude="longitude",
color=alt.Color(
"dir", scale=alt.Scale(domain=[0, 360], scheme="rainbow"), legend=None
),
angle=alt.Angle("dir", scale=alt.Scale(domain=[0, 360], range=[180, 540])),
size=alt.Size("speed", scale=alt.Scale(rangeMax=500)),
).project("equalEarth")