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',
)
|
|
|
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
quantitative (Q) |
a continuous real-valued quantity |
ordinal (O) |
a discrete ordered quantity |
nominal (N) |
a discrete unordered category |
temporal (T) |
a time or date value |
Encoding Options
field |
field to encode |
axis |
axis's gridlines, ticks, labels |
X, Y |
bin |
True: bin a quatitative 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.layer(chart1, chart2) |
chart1 + chart2 |
alt.hconcat(c1, c2) |
chart1 | chart2 |
alt.vconcat(c1, c2) |
chart1 & chart2 |
chart.facet(facet, row, column) |
as a method |
chart.repeat(row, column) |
as a method |
|
|
|