liveBook · Manning

Imperative visualization

As explained in Data Storytelling with Altair and AI

Imperative visualization is a programming approach in which code specifies the individual steps for constructing a visualization.

Imperative visualization specifies the individual steps required to construct a chart. With Matplotlib, code explicitly sets coordinates, axes, titles, labels, styling, and other visual elements. This gives direct control, but usually requires more construction detail than declarative visualization. section 1.2 section 2.1

Plotting square numbers with Matplotlib

A small line chart illustrates the approach: provide x and y values, call plt.plot, set the title, label both axes, and display the result. A larger Matplotlib workflow similarly prepares tourist-arrival data, loops through countries, and draws chart elements separately. By contrast, Altair receives a DataFrame and encodes fields declaratively. section 1.2 section 2.3.4

Listing 1.1 Imperative library
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

plt.plot(x, y)
plt.title('Square Numbers')
plt.xlabel('X')
plt.ylabel('Y')

plt.show()

Inspect the complete compact example, including the plot call, title, axis labels, and display step. section 1.2

How Data Storytelling with Altair and AI covers it

How deep it goes
Explains manual chart construction through axes, labels, styling, loops, and data preparation, but stops short of library internals.
Examples
Uses a square-numbers line chart and a tourist-arrivals chart with separate lines for each country.
What it assumes
Assumes basic Python use and introduces the distinction between manual and declarative chart construction.
What you can do after
Build it from scratch in Matplotlib by preparing data and specifying chart elements individually.
How it connects
Contrasts with declarative visualization and connects to Matplotlib, Altair, and data storytelling.

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.