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
- The question what should the reader see?
-
result = orders.groupby(...).size()a small table: x and y -
result.plot(kind='bar')table becomes marks - Title and labels units, sorted, zero baseline
- 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.
- 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.
plotmaps 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.- 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
- One bar per reason, sorted from largest to smallest. The eye reads the ranking without hunting through the chart.
changed_mind($132,949) anddamaged($128,729) add up to $261,678, more than double the $109,595 oflateandwrong_itemtogether.- 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)
- A histogram does not show categories, it shows how one number is spread out.
plt.histcuts the values into equal bins and counts how many fall into each. - 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.
- 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.
Not quite. That shows how many orders there are over time. It says nothing about how large each one is.Try another answer.
Right. The question is about how one number, order value, is spread out. A histogram counts orders per value bin, so the tall bar on the left and the long tail on the right answer it directly.
Not quite. That compares the mix of statuses between channels. The size of the orders is not in it.Try another answer.
Not quite. order_id is a label that grows with time, not a measure. The cloud of points would show no meaningful relationship and no counts.Try another answer.
Lesson done: it is ticked on the map.