Skip to content
Start free

When to use a scatter plot?

Find out whether more cold drinks sell on hot days with a scatter plot, and review the five questions by choosing the chart for each one.

Free course. Your Maestro, an AI, .

The Tlaquepaque store manager has a hunch: "we sell more horchata on hot days". She wants to know if it's true so she can decide how much to make. It's a relationship question: she has two measures for each day (the high temperature and the cold drinks sold) and wants to know whether, when one goes up, the other does too.

The chart that answers that is the scatter plot: one dot per case (here, per day), with one measure on the bottom axis and the other on the left. The dots aren't joined, because there's no path from one day to the next: each dot stands on its own, and what you read is the shape of the cloud they make together.

Try it

Someone already made a chart with this data: cold drinks day after day, in April and May. Look at the drawing and ask yourself whether it answers the manager's question. Then fix it.

The question is whether more drinks sell on the hottest days. Make two changes (the columns are in Spanish: fecha is the date, temperaturamaxc the high in °C, bebidasfrias the cold drinks sold): 1. Change markline() to markpoint(): one dot per day, not joined. 2. In x, change "ut

Your turn

The question is whether more drinks sell on the hottest days. Make two changes (the columns are in Spanish: fecha is the date, temperatura_max_c the high in °C, bebidas_frias the cold drinks sold):

  1. Change mark_line() to mark_point(): one dot per day, not joined.
  2. In x, change "utcyearmonthdate(fecha):T" (each day, in order) to "temperatura_max_c:Q". The Q says it's a quantity.

You're done when you see a cloud of dots that rises to the right. If you like, a third change: write x=alt.X("temperatura_max_c:Q", scale=alt.Scale(zero=False)) so the axis doesn't start at zero and the cloud uses the full width.

The chart redraws when you pause typing, or right away with Run.

Ready to run your code.

Data: dias-calor, 61 rows

Enter saves a cell and Escape leaves it as it was. Leave a cell empty for a missing value.

The exercise's data, "dias-calor". Your edits run with your code.
RowRemove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Page 1 of 4

Run it yourself

How to read the cloud

The earlier line answered "how did sales change day after day?", and to answer the temperature question you'd have had to find another chart and compare the two from memory. The cloud answers it on its own. Read it in three steps:

  1. Which way does it go? This one rises to the right: the hottest days are at the top. On the coolest day, at 24.5 degrees Celsius, 117 drinks sold; on the hottest, at 36 degrees, 265.
  2. How tight is it? It's not a perfect line: at the same temperature there are better days and worse days. The relationship is clear, but not exact. It's good for planning, not for guessing one particular day.
  3. Any odd dots? The day with the most drinks (272) wasn't the hottest: it was Saturday, May 3, at 33.9 degrees. Weekends sell more even when it's not as hot.

That third point carries a warning that holds for any relationship: two things moving together doesn't prove one causes the other. Here heat makes sense as a cause, but if the hot days had fallen on weekends, the cloud would rise just the same for another reason. The chart shows they go together; the why is up to the reader.

If you have a hunch like that at work ("when this happens, that happens"), tell your Maestro and ask what data you'd need to draw it.

Check yourself: In the cloud, the hotter days have more drinks sold. What can you say with this chart?

Saw two things rising together in your data and not sure if one causes the other? Ask your Maestro what else you'd check.

Review: the five questions

You now have a chart for each of the five questions. Before moving on to reading other people's charts, pull it all together with one more case. Think of your answer before you choose.

Check yourself: La Espiga's director asks four questions. Which of these question-and-chart pairs is WRONG?