Altair Marks & Encodings

🎨 Mark types

alt.Chart(df).mark_point()          # scatter points
alt.Chart(df).mark_circle()             # filled circles
alt.Chart(df).mark_square()                # filled squares
alt.Chart(df).mark_line()                     # line
alt.Chart(df).mark_line(point=True)              # line + visible points
alt.Chart(df).mark_bar()                            # bar chart
alt.Chart(df).mark_area()                              # filled area
alt.Chart(df).mark_rect()                                 # heatmap-style cells
alt.Chart(df).mark_arc()                                     # pie / donut
alt.Chart(df).mark_boxplot()                                    # box plot
alt.Chart(df).mark_tick()                                          # tick marks (strip plot style)
alt.Chart(df).mark_text()                                              # text labels as marks
alt.Chart(df).mark_rule()                                                  # reference lines
alt.Chart(df).mark_geoshape()                                                 # maps

🎯 Encoding channels

alt.Chart(df).mark_point().encode(
    x="col1",
    y="col2",
    color="category",
    size="value",
    shape="group",
    opacity="confidence",
    tooltip=["col1", "col2", "category"]
)
ChannelMaps a variable to
x, yposition
colorcolor
sizepoint/mark size
shapemarker shape (point marks only)
opacitytransparency
tooltiphover info (list of columns)
column, rowsmall multiples β€” see Altair Composition & Layouts
orderdraw/stacking order
textlabel content (mark_text only)

πŸ“Š Bar chart

alt.Chart(df).mark_bar().encode(x="category:N", y="value:Q")
alt.Chart(df).mark_bar().encode(x="category:N", y="value:Q", color="group:N")     # grouped/stacked automatically
alt.Chart(df).mark_bar().encode(y="category:N", x="value:Q")                         # horizontal β€” just swap x/y

πŸ“ˆ Line chart

alt.Chart(df).mark_line().encode(x="date:T", y="value:Q", color="category:N")

πŸ”΅ Scatter with multiple channels

alt.Chart(df).mark_circle().encode(
    x="horsepower:Q",
    y="mpg:Q",
    color="origin:N",
    size="weight:Q",
    tooltip=["name", "horsepower", "mpg"]
)

tooltip=[...] is nearly free interactivity β€” always worth adding once a chart has more than 2-3 encoded variables, so hidden context is one hover away.

πŸ–ŒοΈ Mark-level styling (fixed, not data-driven)

alt.Chart(df).mark_bar(color="steelblue", opacity=0.8)
alt.Chart(df).mark_point(size=100, filled=True)
alt.Chart(df).mark_line(strokeWidth=3, strokeDash=[5,5])

Setting color= inside mark_bar(color=...) is a FIXED color for every mark. Setting color= inside .encode(color=...) is DATA-DRIVEN. Easy to mix these up.

πŸ”— Next

Altair Data Types & Transformations Β· Altair Interactivity