Python · Chapter 11 · Concept lesson · 7 min read

A chart is a table drawn with marks

Every chart is a small table mapped to marks: positions, lengths, bins. Decide the question first, shape the table to match, and the chart type and its honest axis follow.

The idea

A chart is not a picture of your data. It is your data turned into marks: a point whose height is a number, a bar whose length is a number, a rectangle whose height is a count. Each mark comes from a row of a table, and the table is what the chart can show you. Nothing more.

This explains why the order of work is fixed. First the question (what should a reader see?), then the small table that answers it (one row per bar or point), then the chart. Choosing a chart type before the table is how people end up with a pie of 40 slices.

Figure 1

From a question to a chart

  1. The question what should the reader see?
  2. result = orders.groupby(...).size() a small table: x and y
  3. result.plot(kind='bar') table becomes marks
  4. Title and labels units, sorted, zero baseline

Step 1 of 4 Start with the sentence the chart has to support, such as 'which return reasons cost the most?'. It picks the chart, not the other way round.

  1. Start with the sentence the chart has to support, such as 'which return reasons cost the most?'. It picks the chart, not the other way round.
  2. Shape the data into a small table first: one row per bar or per point. Here, refund dollars per reason. Everything you plot is this table, and the check reads it.
  3. plot maps each row to a mark: a position on a line, a bar's length. matplotlib draws what the table says, so a wrong table gives a precise, beautiful, wrong chart.
  4. Labels, sort order and the axis come last. They decide whether the reader sees the truth quickly or has to hunt for it.

Why it exists

A table of 36 monthly numbers is something you read; a line chart of the same 36 numbers is something you see. The Black Friday spike jumps out in under a second, and nobody had to find it. That is the only job of a chart: make a pattern visible faster than a table can.

It follows that the pattern has to be the one the question asks about. The same orders can be drawn as a trend over time, as a comparison of channels, as a spread of order values. Those are three questions and three different tables.

There is a second reason charts matter to an analyst: they are where your audience catches your mistakes. A bar for returns that is ten times too tall, a line that jumps in a month where nothing happened, a histogram with a bar at minus $1,209: each is a data problem you would have missed in a table of averages. Drawing the data is part of checking it, not only of presenting it.

How it works under the hood

The question picks the chart

The question is about Draw a The table has
change over time line one row per day, week or month
comparing categories bar (sorted) one row per category
how values are spread histogram one row per observation
two numbers moving together scatter one row per item, two numeric columns
what a total is made of stacked bar one row per group, one column per part

Most mistakes are a mismatch here, and you can spot one by looking at the table: if the rows are categories, a line is wrong; if they are days, a bar per day is probably too busy. Lines connect their points and say "this leads to that", so a line through channels (which have no order) invents a trend. Bars say "these are separate things".

Bars: sort them, start at zero

A bar chart encodes a value as length, and length only means something from a common baseline.

Figure 2

Refund dollars by return reason, largest first

$0 $37,500 $75,000 $112,500 $150,000 Refunded changed_mind: $132,949damaged: $128,729late: $57,860wrong_item: $51,735 changed_minddamagedlatewrong_item

Step 1 of 3 One bar per reason, sorted from largest to smallest. The eye reads the ranking without hunting through the chart.

  1. One bar per reason, sorted from largest to smallest. The eye reads the ranking without hunting through the chart.
  2. changed_mind ($132,949) and damaged ($128,729) add up to $261,678, more than double the $109,595 of late and wrong_item together.
  3. Bars encode value as length, and length from zero. The first bar is only 2.6 times the size of the last because it is 2.6 times the dollars. That promise is why bar charts start at zero.

Sort the bars by value unless the categories have a natural order, such as months or size bands. A ranking is the point of most bar charts, and it should be visible without effort. Horizontal bars (kind='barh') are better when the labels are long.

Histograms: counting inside bins

A histogram takes one numeric column and counts how many values fall into each bin. The bin width is a choice: too wide and the shape disappears, too narrow and every bar is noise. For money, round widths like $100 are easier to read than whatever the library picks.

Figure 3

Order value in $100 bins (orders under $1,000)

0 1,000 2,000 3,000 4,000 Orders 0-99: 3,139100-199: 1,879200-299: 1,331300-399: 1,051400-499: 751500-599: 584600-699: 452700-799: 395800-899: 312900-999: 257 0-99200-299400-499600-699800-899 median $269

Step 1 of 3 A histogram does not show categories, it shows how one number is spread out. plt.hist cuts the values into equal bins and counts how many fall into each.

  1. A histogram does not show categories, it shows how one number is spread out. plt.hist cuts the values into equal bins and counts how many fall into each.
  2. The tallest bin is the cheapest one: 3,139 orders under $100. The bars fall steadily to the right, a long tail of larger orders.
  3. The median order is $269, far below the mean of $543, because a few very large orders pull the mean up. Here the shape of the data says more than any single average.

Of the 12,000 orders, 10,151 are under $1,000 and fill these bins, 1,843 are $1,000 or more and 6 are negative, which is what a few of the bad quantities do to a total. A histogram makes that sort of surprise visible. A mean could never show it.

Scatter, lines and stacks

A scatter plot puts one item per point, with two numbers deciding where. It answers "do these move together?". A trend line through it is a summary, not proof. For several lines, the colour and the legend must say which is which, and the lines must share an axis. A stacked bar shows a total and its parts: it is easy to read the bottom segment and the total, and hard to compare the middle ones, so put the part that matters at the bottom.

What the check sees

In this game the page checks the numbers you store in result, not the pixels. That is a useful habit anywhere: keep the plotted table in a variable you can print, test or compare. A chart someone can't verify is only an opinion.

Common misconceptions

"Pick the chart type that looks best"

Pick the one that matches the question. A pie, a 3D bar and a wiggly line can all be made to look attractive, and all of them can answer a question you did not ask. If you cannot say in one sentence what the reader should notice, you are not ready to choose a chart.

"Zooming the axis shows the trend better"

For lines, a non-zero baseline can be fine, because position, not length, carries the value. For bars it lies. Yearly orders are 3,171, 4,046 and 4,783: real growth of 1.5 times from 2023 to 2025. Start the bars at 3,000 and the 2025 bar is 10.4 times as tall as the 2023 one. Same numbers, a different claim. If you must zoom, use a line, and say so in the label.

"More chart elements mean a better chart"

Every extra colour, gridline and label is something the reader has to decode. Remove anything that does not help answer the question: if deleting a gridline changes nothing a reader would conclude, delete it. A direct title that states the finding ("Refunds are driven by two reasons") does more than a legend and a rainbow.

Check yourself

One question. Answering it ticks this lesson off on the map; it never locks a level.

A colleague asks: 'Are most of our orders small, and do a few large ones make up the rest?' Which chart answers it best, and from which table?

Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.