Sub topic 8
Graphing a Line from Its Equation
This chapter assumes you can plot points on the coordinate plane, work with signed numbers and fractions, and solve one-step and two-step equations. It also assumes you know that in y = mx + b, m is the slope (rise over run) and b is the y-intercept. Here you will turn that equation into a drawn line, check the result, and avoid the usual mistakes.
Why the equation tells you how to draw the line
A line has a constant rate of change. That means the same step to the right always produces the same change in height. The equation y = mx + b records two facts that are enough to draw the whole line:
- b is where the line crosses the y-axis. It is the point (0, b).
- m is the change in y for each 1 unit of change in x. It tells you how to move from one point on the line to the next.
So graphing is a two-part procedure: place one anchor point, then use the slope to find more points.
The standard procedure
Take y = (2/3)x - 1.
- Read the intercept. Here b = -1, so plot (0, -1).
- Write the slope as a fraction, rise over run. Here m = 2/3, so the rise is 2 and the run is 3.
- From (0, -1), move up 2 and right 3. You land on (3, 1). Plot it.
- Repeat from the new point to get (6, 3). Plot it.
- Move in the opposite direction as well: down 2 and left 3 from (0, -1) gives (-3, -3).
- Draw a straight line through the points and extend it past them with arrows on both ends.
Three points are better than two. Two points always lie on some line, so they cannot reveal an error. If the third point is not on the line through the first two, you made a mistake somewhere.
Handling the sign of the slope
The sign of m controls which way you step. The rule is that you pick one of the two numbers (rise or run) to carry the negative sign, and the other stays positive.
For y = -(3/4)x + 5, plot (0, 5). The slope is -3/4, which can be read two equivalent ways:
- Rise -3, run 4: move down 3 and right 4, landing on (4, 2).
- Rise 3, run -4: move up 3 and left 4, landing on (-4, 8).
Both points are on the same line. Using both gives you points on each side of the intercept. What you must not do is put a negative on both numbers. A rise of -3 and a run of -4 gives a slope of +3/4, which is a different line.
| Slope m | Rise, run | Direction when moving right |
|---|---|---|
| 2 | 2, 1 | Up 2 for each 1 right |
| -2 | -2, 1 | Down 2 for each 1 right |
| 1/2 | 1, 2 | Up 1 for each 2 right |
| -1/2 | -1, 2 | Down 1 for each 2 right |
| 0 | 0, 1 | No change in height |
An integer slope such as 2 is written as 2/1 so that you have a run to count.
Special cases
Slope zero
In y = 4, the slope is 0 and the line is horizontal. Every point has y = 4, so the line passes through (0, 4), (1, 4), (-7, 4), and so on. It can be written as y = 0x + 4.
Missing intercept term
In y = 3x, the term b is missing, so b = 0. The line passes through the origin (0, 0). From there, rise 3 and run 1 gives (1, 3).
Equation with a negative intercept
In y = x - 6, the coefficient of x is 1 (it is not missing), so m = 1/1. The intercept is -6. Plot (0, -6), then step up 1 and right 1 to get (1, -5).
Vertical lines
An equation such as x = 3 is not in slope-intercept form. The slope is undefined, and the line cannot be graphed by the procedure above. Plot the points (3, 0), (3, 1), (3, -2) and draw the vertical line through them. In general, x = k is a vertical line through (k, 0).
Fractional or decimal intercepts
If b is a fraction such as 5/2, plot it at 2.5 on the y-axis. If the grid is too coarse for that, start from a different point. Pick an x value that makes mx a whole number, then compute y. For y = (1/2)x + 5/2, using x = 1 gives y = 3, so (1, 3) is on the line and is easier to place.
Equations that are not yet in slope-intercept form
If the equation is written as 2y = 6x - 4, you must solve for y first.
- Divide every term by 2: y = 3x - 2.
- Read b = -2 and m = 3.
The most common error here is dividing only one term. If you divide 2y by 2 you must also divide 6x and -4. The details of converting from standard form Ax + By = C are covered in a later chapter. For now, any equation can be graphed once it is solved for y.
Checking your line with a point
Pick a point on your drawn line that has clear coordinates, and substitute it into the equation. For y = (2/3)x - 1, the point (3, 1) gives:
(2/3)(3) - 1 = 2 - 1 = 1
The left side is y = 1, which matches. If a plotted point fails this check, either the arithmetic or the plotting is wrong.
You can also check that the y-intercept is correct by setting x = 0, and check the slope by comparing two points on your line with the formula (y2 - y1) / (x2 - x1).
Generating the points in code
A table of values is the same procedure in computed form. This program lists points on a line, then verifies that each step has the same slope. It uses Fraction so there are no rounding errors.
from fractions import Fraction
def points_on_line(m, b, xs):
return [(x, m * x + b) for x in xs]
m = Fraction(2, 3)
b = Fraction(-1)
pts = points_on_line(m, b, [-3, 0, 3, 6])
for x, y in pts:
print(f"({x}, {y})")
# Check that every consecutive pair has the same slope
slopes = {
(y2 - y1) / (x2 - x1)
for (x1, y1), (x2, y2) in zip(pts, pts[1:])
}
print("slopes:", slopes) # slopes: {Fraction(2, 3)}The output lists (-3, -3), (0, -1), (3, 1), and (6, 3). Notice that the x values were chosen as multiples of 3 so that the y values are whole numbers. That is the same trick you use by hand: choose x values that cancel the denominator of the slope.
If you want an actual picture, the plotting library matplotlib can draw it:
import matplotlib.pyplot as plt
m, b = 2 / 3, -1
xs = [-6, 6]
ys = [m * x + b for x in xs]
plt.plot(xs, ys)
plt.scatter([0], [b], color="red") # the y-intercept
plt.axhline(0, color="gray", linewidth=0.5)
plt.axvline(0, color="gray", linewidth=0.5)
plt.grid(True)
plt.title("y = (2/3)x - 1")
plt.show()Two points are enough for the computer, because it does not make slips in arithmetic. By hand, use three.
Common errors
- Swapping rise and run. A slope of 2/3 means up 2 and right 3, not up 3 and right 2. The line you draw would be steeper than it should be.
- Plotting b on the x-axis. The intercept b belongs at (0, b), not (b, 0).
- Using the wrong sign. If m is negative, the line falls as you move right. Check your drawing against this fact. A line that rises when m < 0 is wrong.
- Counting from the origin. After plotting (0, b), start counting from that point, not from (0, 0).
- Stopping the line at the plotted points. A line extends forever, so draw arrows at both ends.
- Uneven scales. If the x-axis and y-axis use different units per grid square, the line looks steeper or flatter than its slope suggests. Count in grid units, and keep the scales equal when you can.
Worked example: from a description to a graph
A taxi charges a flat fee of $3 plus $2 per mile. The cost C in dollars after x miles is C = 2x + 3. Treat C as y.
- The intercept is 3, so plot (0, 3). This is the cost of a trip of zero miles, the starting fee.
- The slope is 2, or 2/1. From (0, 3), move up 2 and right 1 to get (1, 5), then (2, 7).
- Draw the line starting at (0, 3) and going right. Negative miles make no sense, so this graph is a ray, not a full line. Arrows are only on the right end.
The context changes the domain, which is the set of allowed x values. The procedure is the same, but you only draw the part that makes sense in the situation.
Practice
Exercise
Graph y = -(2/5)x + 3. List three points that lie on the line, and say whether the line rises or falls from left to right.
Show answer
The intercept is (0, 3). The slope -2/5 can be read as rise -2, run 5. Moving down 2 and right 5 from (0, 3) gives (5, 1). Repeating gives (10, -1). Moving up 2 and left 5 gives (-5, 5). Three points: (-5, 5), (0, 3), (5, 1) (and (10, -1) also works). The slope is negative, so the line falls from left to right.
Exercise
The equation 3y = 6x + 9 is not solved for y. Rewrite it in slope-intercept form, then state the slope, the y-intercept, and two points on the line.
Show answer
Divide every term by 3: y = 2x + 3. The slope is 2 and the y-intercept is 3. Two points are (0, 3) and (1, 5). Check (1, 5) in the original equation: 3(5) = 15 and 6(1) + 9 = 15, so it holds.
Exercise
A student graphs y = (3/4)x + 2 by plotting (0, 2) and then moving up 4 and right 3, landing at (3, 6). What went wrong, and what is the correct second point?
Show answer
The student swapped rise and run. The slope 3/4 means rise 3 and run 4, so from (0, 2) move up 3 and right 4 to reach (4, 5). Check: (3/4)(4) + 2 = 5.