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
