Nominal data consists of distinct categorical labels with no intrinsic order. In Altair, declare a nominal column when mapping categories to visual channels such as position, color, or shape. section 2.1.3 section 3.2.1
Choose the nominal type when the labels identify groups rather than quantities or ranked values:
- Use `Name:N` for categorical labels on an axis, as in a bar chart with age on x and names on y. section 2.1.3
- Use `Country:N` to separate lines by country through color; the labels identify series but do not imply a ranking. section 2.3.1
- Keep nominal data distinct from ordinal data, which has an inherent order, and quantitative data, which represents numerical values. section 3.2.1
Encoding a nominal column in Altair
A DataFrame can contain names, ages, and cities. Encode age quantitatively and names nominally: `chart = alt.Chart(df).mark_bar().encode(x='Age:Q', y='Name:N')`. The `:N` shorthand tells Altair to treat `Name` as an unordered category. 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 the complete DataFrame and Altair encoding example, including nominal names and chart export. section 2.1.3



