Show Menu
Cheatography

Python Altair Cheat Sheet (DRAFT) by

Altair is a declarative statistical visualization library for Python

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basics

import altair as alt

from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)

Gallery

 

Encodings

Channels
X, Y, X2, Y2
Mark Property
Color, Fill, Size, Opacity
Text
Text (for labels), Tooltip
Facet
Column, Row, Facet
Others
Detail, Order
Short form is the same without first Capital letter

Encoding Data Types

quanti­tative (Q)
a continuous real-v­alued quantity
ordinal (O)
a discrete ordered quantity
nominal (N)
a discrete unordered category
temporal (T)
a time or date value
(short­hands)

Encoding Options

field
field to encode
axis
axis's gridlines, ticks, labels
X, Y
bin
True: bin a quatit­ative var.
X, Y
 

Marks

mark_area()
mark_line()
mark_bar()
mark_point()
mark_circle()
mark_rect()
mark_text()
mark_tick()
mark_boxplot()
mark_errorband()
mark_errorbar()

Compound Charts

alt.la­yer­(ch­art1, chart2)
chart1 + chart2
alt.hc­onc­at(c1, c2)
chart1 | chart2
alt.vc­onc­at(c1, c2)
chart1 & chart2
chart.f­ac­et(­facet, row, column)
as a method
chart.r­ep­eat­(row, column)
as a method
 

Altair Cheat Sheet