liveBook · Manning

Visual mark

As explained in Data Storytelling with Altair and AI

A mark is a graphical primitive in a visualization grammar that represents data items through visual shapes such as points, lines, or bars.

A visual mark is the visible element that represents data in a chart. Bars, points, lines, areas, heatmap rectangles, and text are marks. In a declarative visualization, choose a mark to state the type of chart to draw; use encodings separately to map data fields to visual properties such as position, color, and size. section 2.1.2 section 3.4

In Altair, a chart starts with data, then receives a mark and encodings. The mark answers “what visual form should represent the data?” while encodings answer “which fields control the axes, color, size, or other channels?” A mark alone does not make the chart ready to display meaningful data. section 2.1 section 2.5

Start with a bar mark

Attach mark_bar() to an Altair chart to request a bar chart. The same pattern supports mark_line() for a line chart and mark_circle() for a scatter plot. chart = alt.Chart(df).mark_bar() section 2.1.2

Select a mark that fits the visual form needed:

  • Use mark_bar() for a bar chart, mark_area() for a filled-area chart, or mark_arc() for a pie chart. section 3.2.2
  • Use mark_line() for a line chart, mark_circle() or mark_point() for scatter plots, and mark_rect() for heatmaps. section 3.2.2
  • Use mark_geoshape() for geographic shapes, mark_rule() for an axis-spanning line, or mark_text() for text. section 3.2.2

Mark properties can set a constant visual value. For example, mark_circle(size=5) gives every circle the same size. When size should vary by a DataFrame column, place size in the encoding instead; encodings map data to visual properties, whereas a mark property fixes a value. section 3.2.2

Table 3.2 The main mark types provided by Altair
Method
Description
mark_arc()
A pie chart
mark_area()
A filled-area chart
mark_bar()
A bar chart
mark_circle()
A scatter plot with filled points
mark_geoshape()
A geographic shape
mark_line()
A line chart
mark_point()
A scatter plot with configurable points
mark_rect()
A filled rectangle for heatmaps
mark_rule()
A vertical or horizontal line spanning the axis
mark_text()
A text

Browse the available Altair mark methods when choosing a visual form, including bars, lines, points, heatmap rectangles, rules, text, and geographic shapes. section 3.2.2

Marks also appear in Vega-Lite specifications. A Vega-Lite JSON specification separates data, encoding, mark, and layer; the mark section names a type such as line. A layer can combine marks, for example a line and points, in one chart. section 3.1.2

Describe a mark for Copilot

When asking Copilot to generate an Altair chart, state the action, library, and mark type explicitly: “Draw a bar chart named chart in Altair.” Review the generated code and adapt it to the requirements. section 4.4.2 section 4.4

How Data Storytelling with Altair and AI covers it

How deep it goes
Distinguishes mark types and constant mark properties from data-driven encoding channels, without detailing individual property options.
Examples
Uses bar, line, scatter, heatmap, geographic, rule, and text marks, plus a constant-size circle and layered line-point chart.
What it assumes
Assumes an Altair chart and DataFrame, then teaches marks as a basic chart component.
What you can do after
Apply it via Altair by selecting mark_<type>() and separating fixed mark properties from field-driven encodings.
How it connects
Connects marks with Altair charts, encodings, conditions, compound charts, interactivity, Vega, and Vega-Lite.

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.