Sub topic 9
Plotting Points from a Table of Values
What this chapter covers
A table of values lists input numbers and the output numbers that go with them. Each row becomes one ordered pair, and each ordered pair becomes one point on the coordinate plane. This chapter assumes you can do the following:
- Plot and read points in all four quadrants.
- Choose a scale for each axis.
- Recognise that the order in (x, y) matters.
Once the points are on the plane, you can look at their shape. The shape shows the pattern in the table.
From table to ordered pairs
A table has two columns. The left column holds x values, the independent quantity. The right column holds y values, the dependent quantity. Each row gives one ordered pair (x, y).
Here is a table where y is always 2 more than x:
| x | y |
|---|---|
| -2 | 0 |
| -1 | 1 |
| 0 | 2 |
| 1 | 3 |
| 2 | 4 |
The rows give the pairs (-2, 0), (-1, 1), (0, 2), (1, 3) and (2, 4).
Tables often come from a rule. The rule here is y = x + 2. You can generate the table yourself by substituting each x into the rule. You can also go the other way and look for the rule in a table.
def make_table(rule, xs):
return [(x, rule(x)) for x in xs]
table = make_table(lambda x: x + 2, range(-2, 3))
print(table)The output is [(-2, 0), (-1, 1), (0, 2), (1, 3), (2, 4)].
A procedure for plotting a table
Follow the same steps each time. They prevent most errors.
- Read the smallest and largest x values, then the smallest and largest y values.
- Choose an axis range and a scale for each axis that covers those values (see the scale chapter).
- Draw the axes and label them with the quantities and units, if the table has any.
- For each row, start at the origin. Move horizontally by x, then vertically by y. Mark the point.
- Tick off each row as you plot it, so you do not skip or repeat one.
- Look at the finished set of points and describe the pattern.
Worked example: a table with negative values
Plot this table.
| x | y |
|---|---|
| -3 | 6 |
| -1 | 2 |
| 0 | 0 |
| 1 | -2 |
| 3 | -6 |
The x values run from -3 to 3. The y values run from -6 to 6. An axis from -7 to 7 on both axes, with a tick at every 1 or every 2, fits everything.
The points are:
- (-3, 6): 3 left, 6 up. Quadrant II.
- (-1, 2): 1 left, 2 up. Quadrant II.
- (0, 0): the origin.
- (1, -2): 1 right, 2 down. Quadrant IV.
- (3, -6): 3 right, 6 down. Quadrant IV.
The points fall along a straight line that slopes down from left to right. Each time x increases by 1, y decreases by 2. The rule is y = -2x. The line passes through the origin because x = 0 gives y = 0.
You can plot the table with the same style of code used earlier in this tutorial:
import matplotlib.pyplot as plt
xs = [-3, -1, 0, 1, 3]
ys = [6, 2, 0, -2, -6]
fig, ax = plt.subplots()
ax.scatter(xs, ys)
for x, y in zip(xs, ys):
ax.annotate(f"({x}, {y})", (x, y), textcoords="offset points", xytext=(5, 5))
ax.axhline(0, color="black")
ax.axvline(0, color="black")
ax.set_xlim(-8, 8)
ax.set_ylim(-8, 8)
ax.set_aspect("equal")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.grid(True)
plt.show()Reading the pattern
The pattern in a table shows up in two places. You can find it in the numbers, and you can see it in the points.
In the table
Look at how y changes when x changes by a steady amount.
- If y changes by the same amount each time, the points lie on a straight line. In the table above, y drops by 2 for every step of 1 in x.
- If the change in y itself keeps growing or shrinking, the points lie on a curve.
- If y stays the same, the points lie on a horizontal line.
Here is a table where the changes are not constant:
| x | y |
|---|---|
| -2 | 4 |
| -1 | 1 |
| 0 | 0 |
| 1 | 1 |
| 2 | 4 |
From x = -2 to -1, y changes by -3. From -1 to 0, it changes by -1. Then it changes by +1, then +3. The changes are not constant, so these points are not on a line. They form a U shape, which is the graph of y = x².
On the plane
A quick visual check is also useful.
| What you see | What it suggests |
|---|---|
| Points in a straight line rising to the right | y increases at a steady rate as x increases |
| Points in a straight line falling to the right | y decreases at a steady rate as x increases |
| Points in a horizontal line | y is constant |
| Points in a vertical line | x is constant, which cannot be a table of y against x for a function |
| Points in a U or arch | y changes at a changing rate |
Note that this table can only show a function if each x appears once. A vertical line has the same x with many y values, so it fails that test.
Edge cases and common errors
Swapped coordinates
The most common error is plotting (y, x) instead of (x, y). For the point (-3, 6), the swap gives (6, -3), which is in quadrant IV rather than quadrant II. Always take the first column as horizontal movement.
Uneven x spacing
Tables do not always use x values 1 apart. The table above skips x = 2 and x = -2. Each point must still go at its true x position. Do not place the points at equal gaps because the rows look evenly spaced on the page.
xs = [0, 1, 3, 7]
ys = [1, 3, 7, 15]
for x, y in zip(xs, ys):
print(f"x = {x}, y = {y}")The gaps between x values are 1, 2 and 4. Plotted at their true positions, the points are not evenly spread along the x-axis.
Joining the points
Whether to connect the points depends on what the numbers mean.
- If x can take any value in between, such as time or distance, you can join the points. Joining is an estimate of the values between the rows.
- If x can take only whole-number values, such as the number of tickets bought, leave the points separate. A line between them would suggest 2.5 tickets.
Scales that mislead
If y values are large and x values are small, one scale for both axes can squash the points together. You can use different scales on the two axes. Label each one clearly, and remember that the plot no longer has equal scale. Angles and distances will look different from the true ones.
Missing zero
If the table includes x = 0, the point lies on the y-axis. If it includes y = 0, the point lies on the x-axis. These are easy to place in the wrong quadrant. Check the signs of both coordinates and use the quadrant rules from the earlier chapter.
def where(x, y):
if x == 0 and y == 0:
return "origin"
if y == 0:
return "on the x-axis"
if x == 0:
return "on the y-axis"
return "in a quadrant"
for pair in [(-3, 6), (0, 2), (4, 0), (0, 0)]:
print(pair, where(*pair))Real-world tables
Tables from real situations work the same way, with labelled axes and units.
| Hours worked (x) | Pay in dollars (y) |
|---|---|
| 0 | 0 |
| 2 | 30 |
| 4 | 60 |
| 6 | 90 |
The points (0, 0), (2, 30), (4, 60) and (6, 90) lie on a line. Pay rises by 15 dollars per hour. Only the first quadrant is needed, because neither hours nor pay is negative here. Use an x axis from 0 to 8 and a y axis from 0 to 120. The scale step could be 1 hour on x and 10 or 20 dollars on y.
Using only the quadrants you need gives each point more room.
Checking your plot
Before you move on, run through this list:
- Does the number of points equal the number of rows?
- Does each point have the right signs for its quadrant?
- Are both axes labelled, with a consistent scale and units?
- Does the pattern in the plot agree with the pattern in the numbers?
Exercise
A table has the rows (x, y) = (-2, -5), (0, -1), (2, 3) and (4, 7). Give the quadrant or axis of each point, then say what pattern the points form and write the rule.
Show answer
(-2, -5) is in quadrant III. (0, -1) is on the y-axis. (2, 3) is in quadrant I. (4, 7) is in quadrant I. Each time x increases by 2, y increases by 4, so the change is constant and the points lie on a straight line rising to the right. The slope is 4 / 2 = 2 and the line crosses the y-axis at -1, so the rule is y = 2x - 1.
Exercise
A student plots the table x = 1, 2, 4, 8 with y = 3, 5, 9, 17 and places the four points at equal gaps along the x-axis. What mistake did the student make, and what do the correctly placed points look like?
Show answer
The student ignored the true x values. The gaps in x are 1, 2 and 4, so the points must be spaced by those amounts. Placed correctly, the points (1, 3), (2, 5), (4, 9) and (8, 17) lie on a straight line, because y rises by 2 for every 1 step in x. The rule is y = 2x + 1. Equal gaps would have made the line look curved.