liveBook · Manning

Mark function

As explained in Data Storytelling with Altair and AI

mark_bar() is an Altair API method that specifies bar marks for a chart.

A mark function specifies how Altair represents data visually. Calling mark_bar() on an Altair chart selects bars, while related functions select lines, areas, or points. section 2.1.2 section 3.2.2

Create a bar chart

Append mark_bar() to a chart before adding encodings: chart = alt.Chart(df).mark_bar(). The mark establishes the visual form; encodings then connect data columns to visual properties such as position. Mark properties supplied as arguments remain constant, whereas encoding channels can vary with column values. section 2.1.2 section 3.2.2

Use bars to answer a focused question

A regional homelessness chart uses mark_bar(color='#80C11E'), encodes territory on y and homeless-person counts on x, and sorts bars in descending order. The example also shows that absolute counts can mislead when regions have different populations, so the data may need normalization before charting. section 5.1.1

Listing 2.2 Mark in Altair
chart = alt.Chart(df).mark_bar()

View the minimal Altair statement that applies mark_bar() to a chart. section 2.1.2

How Data Storytelling with Altair and AI covers it

How deep it goes
Defines mark selection and distinguishes constant mark properties from variable encoding channels through concise examples.
Examples
Uses minimal chart construction and a regional homelessness bar chart with color, sorting, titles, and population-aware interpretation.
What it assumes
Assumes familiarity with an Altair chart and DataFrame columns while teaching mark selection before detailed chart configuration.
What you can do after
Build it from scratch by selecting a bar mark, adding encodings, and configuring a focused Altair comparison.
How it connects
Connects visual marks with encoding channels, bar charts, line charts, scatter plots, and data normalization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.