Quantitative data contains numerical values that represent amounts or measurements. In visualization, it maps naturally to positions, sizes, colors, and other visual properties through a quantitative encoding. section 2.1.3 section 3.2.1
Altair marks a quantitative field with Q, either in a shorthand such as `Age:Q` or through a channel's type property. This distinguishes numerical values from nominal categories, ordinal order, and temporal dates. section 2.1.3 section 3.2.1
Use quantitative data to:
- Place measurements on chart axes, such as age, product sales, or tourist arrivals. section 2.1.3 section 3.2.1
- Aggregate numerical records, such as summing tourist arrivals by year and country. section 2.3.1
- Calculate derived measures, such as percentage increases from a selected baseline. section 2.3.1
Encoding age in a bar chart
A DataFrame containing names, ages, and cities can encode `Age:Q` on the x-axis and `Name:N` on the y-axis. The resulting chart represents each person's numerical age against a nominal name. section 2.1.3
Listing 2.3 Encodings in Altair
import pandas as pd
import altair as alt
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Paris', 'London']
} #1
df = pd.DataFrame(data) #2
# Create the chart
chart = alt.Chart(df).mark_bar(
).encode(
x = 'Age:Q',
y = 'Name:N'
)
chart.save('bar-chart.html')
Inspect a runnable Altair example that creates a DataFrame and encodes its numerical Age column with `Age:Q`. section 2.1.3






