Chapter 11 — Charts and Dashboards: “The Console”

A Figure with Multiple Plots: Figure, Axes, and a Grid

16 min

The “Control Room” Deck

The year is 2184, aboard Vault-9. For the first time in months of investigation, the bulkhead to the visualization bay opens. Inside is the “Control Room,” Kotomarket's monitoring center: a wall of dead screens. Only QUERY's terminal is still glowing.

QUERY: A person takes a minute to read a thirty-row table. A line takes a second. I've tested it. Repeatedly. So let's turn on the screens.

L., log #29: The board of directors doesn't read tables. The board of directors looks at pictures. If you want them to listen, learn to communicate with data visually.

You already know the basics: in the “First Look at Data” chapter, you drew a line with plt.plot, labeled the axes, sorted X, and chose a chart type to match the question. In the “Control Room,” you rarely show a single chart. You show a panel, which means you need a way to control each chart separately.

The Sheet and the Plot: Figure and Axes

A Figure is like a sheet of paper: it has a size and can have an overall title, and when you save the result as a PNG, the entire sheet is saved. An Axes is one plotting area on that sheet, with its own coordinate system, title, and lines. A Figure can contain one Axes object or six.

plt.plot(...) and plt.title(...) work with the “current” Axes object: whichever one is active at that moment. That's convenient with a single chart. With four charts, an accidental change of the current Axes can send the next command to the wrong quadrant. So the Control Room rule is simple: store both the Figure and its plots in variables.

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(10, 4))   # sheet + ONE plot, both stored in variables
ax.plot(df['day'], df['visitors'])
ax.set_title('Visitors, April 2184')

Translation Guide: plt.* → ax.*

plt.* commandAxes method
plt.plot(x, y)ax.plot(x, y)
plt.title('...')ax.set_title('...')
plt.xlabel('...') / plt.ylabel('...')ax.set_xlabel('...') / ax.set_ylabel('...')
plt.ylim(0, 100)ax.set_ylim(0, 100)
plt.grid(alpha=0.3)ax.grid(alpha=0.3)

In these pairs, titles, axis labels, and limits use set_* methods. Methods that draw or format content (plot, bar, hist, grid, legend) usually keep the same name without the set_ prefix. Treat that as a useful pattern, not a rule that applies to every Axes method. The title for the entire sheet belongs to the Figure: fig.suptitle('Kotomarket Control Room').

A cadet assembles a two-by-two grid of empty holographic windows, snapping one into a corner slot; a cat sits inside one empty window as if peeking through a small opening.
From one chart to a panel: plt.subplots, indexing axes[row, column], using ax.set_title instead of plt.title, and why different metrics shouldn't share one Y-axis.
Figuresheet of paperaxes[0,0]axes[0,1]axes[1,0]axes[1,1]fig, axes = plt.subplots(2, 2)plt.title()→ current Axes ●ax.set_title()→ a specific AxesFigure is the sheet, Axes is a plot on it
Figure is the sheet; Axes is one coordinate system on it. plt.subplots(2, 2) returns a sheet and a 2 × 2 array containing four Axes, each accessed by its row and column.
One sheet, one Axes, with both stored in variables. The line plt.gca() is ax shows that plt.plot would draw on this exact Axes.
python · pandas

A Grid: One Sheet, Four Plots

plt.subplots(2, 2) divides the Figure into two rows and two columns and returns two things: the Figure and an array of four Axes with shape 2×2. You access a specific Axes just like a cell in a table: row first, then column.

column 0column 1
row 0axes[0, 0]axes[0, 1]
row 1axes[1, 0]axes[1, 1]

A good way to build a panel is one cell at a time. Step one: create an empty grid.

fig, axes = plt.subplots(2, 2, figsize=(12, 7))
print(axes.shape)   # (2, 2)
print(axes.size)    # 4

Step two: fill just one cell and check that you used the one you intended.

axes[0, 0].plot(df['day'], df['visitors'])
axes[0, 0].set_title('Visitors')
axes[0, 0].set_ylabel('People per day')

Step three: fill the remaining three cells the same way. Step four: apply settings that should be shared across the panel.

for ax in axes.flat:            # .flat — iterate over all four Axes as a flat sequence
    ax.grid(alpha=0.3)
    ax.tick_params(axis='x', rotation=45)
fig.suptitle('Kotomarket Control Room: April 2184')
fig.tight_layout()              # adds space so labels do not overlap

A loop over axes.flat is useful for settings that should be identical across all plots. Set the data, titles, and labels for each cell separately.

Three Shape Traps

CallWhat it returnsHow to address it
plt.subplots()one Axes object, not an arrayax.plot(...)
plt.subplots(1, 2)a one-dimensional array of 2 Axesaxes[0], axes[1]
plt.subplots(2, 2)a two-dimensional 2×2 arrayaxes[0, 1], etc.

A common mistake is to write axes[0, 0] for a 1, 2 grid and get an IndexError with the message too many indices. Check the array shape with print(axes.shape) when you're unsure. A single Axes object has no shape.

Another useful argument is sharex=True: every cell uses the same X-axis limits, making it easier to compare dips that happened on the same date. sharey=True is usually a poor fit for a panel of different metrics because it forces the plots to share Y-axis limits. Metrics on smaller scales then get squeezed against the edge of the chart. The next section shows why.

Why Four Metrics Don't Belong on One Y-Axis

Kotomarket's April log covers 28 days and tracks four metrics:

MetricMinimumMaximum
Visitors, people/day14111969
Revenue, $/day$1175.0$1752.0
Buyer conversion, %8.3411.76
Average order value, $$5.5$7.0

Plot all four lines on one Y-axis. Matplotlib has to choose a single range that includes at least the values from $5.5 to 1969, usually with a little extra padding. The axis doesn't have to start at zero. Even so, conversion, which ranges from 8.34 to 11.76, becomes an almost flat line near the bottom: its span is only 3.42, compared with 558 for visitors. On the old scale, this comparison was written as 57 688 / 3,42 ≈ 16 868; after converting the monetary values to dollars, the conversion span is still much smaller than the scale of the largest lines. All four lines are technically visible, but changes in conversion and average order value are very hard to distinguish.

The gap is also clear from the average levels: visitors average ≈1698, while conversion averages ≈10.53%. The ratio is 1698 / 10,53 ≈ 161. This isn't a meaningful comparison of the metrics themselves. It simply shows how far apart their lines will sit on the same numeric scale. The units differ too: visitors, dollars, and percentages shouldn't be measured on one shared scale. That's why the panel uses a grid with one Y-axis for each metric.

QUERY: Putting revenue and conversion on one axis is like weighing a cat and one strand of its fur on the same scale. The scale won't break. You just won't see the strand. I've weighed them. Repeatedly.

The Axis Scale Should Answer the Question

There's one more detail to get right. The rule “the Y-axis must always start at zero” is not universal. Choose the scale based on the question the chart is answering.

Chart questionWhat scale is honest
“How many times larger?” — bars, proportionsstart at zero: truncation distorts the ratio of bar heights
“How much did it change?” — conversion 11.1% → 9.5%a window around the data: this makes the 1.6 pp drop easier to see; the truncation must be clearly visible on the scale
“Is there a rhythm, shape, or outlier?”automatic: the shape matters more than the level

A misleading rule you may hear is: “If the axis doesn't start at zero, the chart is dishonest.” The range itself isn't the problem. A chart becomes misleading when the range doesn't fit the question or when truncation is hidden.

L., log #31: “Marketing showed a chart where the axis started at 96%. A 0.5 pp increase looked like a rocket launch. Everyone applauded. The problem wasn't that the axis was truncated; the caption claimed ‘growth by multiples.’”

Y axis from 012006000the growth looks modestY axis from 990102010101000990the same growth looks hugesame data: 1000 → 1020, that is +2%the scale must match the question you ask
The same data is shown at two different scales. Neither scale is inherently misleading: problems arise when the scale doesn't match the question or when truncation is hidden.
On the left, four metrics share one Y-axis, which makes the smaller ones hard to read. On the right, conversion has its own scale. One sheet, two Axes.
python · pandas
Practice: write the code
Work step by step: first the grid, then ONE quadrant. Create fig, axes = plt.subplots(2, 2, figsize=(12, 7)). Store grid_shape — the shape of the Axes array (axes.shape) and n_axes — the total number of Axes on the sheet (axes.size). Then fill only the top-left quadrant with a line showing visitors by day. Set its title to exactly 'Visitors' and its Y-axis label to exactly 'People per day'. Leave the other three quadrants empty.
python · pandas
Practice: write the code
Now build the full panel and use the numbers to show why a shared Y-axis doesn't work. Calculate span_visitors — the visitors span (maximum minus minimum); span_conv — the conversion span in percentage points (column buyer_conv, rounded to 2 decimal places); and scale_ratio — how many times larger the average visitor level is than the average conversion level (rounded to 1 decimal place). Then build a 2×2 (12, 7) grid: [0,0] visitors, [0,1] revenue, [1,0] conversion, [1,1] average order value. Give each quadrant its own title.
python · pandas
Check yourself
An analyst puts four lines on one chart: visitors (≈1700), revenue (≈$1400), conversion (≈10%), and average order value (≈$6.40), all on one shared Y-axis. What happens?
Check yourself
In the grid fig, axes = plt.subplots(2, 2), you need to title the bottom-right quadrant. Which line sets that title directly, regardless of which Axes is currently active?
Key takeaways
  • Figure is the whole figure; Axes is one plotting area with its own axes. fig, axes = plt.subplots(...) returns a Figure and either one Axes or an array of Axes.
  • Build a panel one quadrant at a time: grid → axes[0, 0] → check → remaining plots → shared settings (axes.flat, fig.suptitle, fig.tight_layout).
  • When moving from plt to Axes, use plt.title → ax.set_title and plt.ylim → ax.set_ylim; drawing methods keep the same names.
  • The return shape matters: plt.subplots() → one Axes, plt.subplots(1, 2) → a one-dimensional array, plt.subplots(2, 2) → a two-dimensional array. If you're unsure, check print(axes.shape).
  • Metrics on very different scales—1698 and 10.53, about 161× apart—are difficult to read on one Y-axis.
  • Choose the axis scale to fit the task: when comparing quantities by bar length, start at zero; when showing small fluctuations, you can use a narrower window around the data. Make a truncated scale clear through its tick marks and explain it in the caption.