Sub topic 4
Choosing a Scale for the Axes
This chapter assumes you can order positive and negative numbers on a number line and that you know how an ordered pair (x, y) names a point. It also assumes you have met the x-axis, y-axis and origin. You will learn how to pick the numbers printed along each axis so that every point you need fits on the plane and can still be read accurately.
What a scale is
A scale is the rule that links distance on the page to value on an axis. It has two parts:
- The interval (or step) is the value difference between two neighboring tick marks. If the ticks read 0, 5, 10, 15, the interval is 5.
- The range is the lowest and highest value the axis shows, for example -15 to 20.
Every axis needs its own scale, and the two axes do not have to use the same one. A graph of temperature against time might label time in hours (interval 1) and temperature in degrees (interval 10). Each axis still needs consistent spacing: equal distances on the page must always mean equal changes in value.
The working model
Choosing a scale is a fitting problem with three constraints.
- Coverage. The range must include every point you need, and it must include 0 so the axes cross at the origin.
- Readability. The interval should be a number that is easy to count by, such as 1, 2, 5, 10, 20, 50 or 100, or a tenth or a hundredth of one of those. Avoid 3, 7 or 15 unless the problem forces them.
- Economy. Aim for roughly 6 to 12 intervals along each axis. Fewer wastes space and makes points cluster. More makes the labels crowded.
Do this separately for x and for y. The two axes will often end up with different intervals.
A worked example by hand
Plot (3, 2), (-4, 5), (-1, -6), (2, -3) and (0, 0).
For x, the values run from -4 to 3, a span of 7. Dividing by about 8 gives a raw step of 0.875. The next friendly step up is 1. Extending to multiples of 1 gives the range -4 to 3, so you might draw -5 to 4 to leave a margin.
For y, the values run from -6 to 5, a span of 11. The raw step is about 1.4, so the next friendly step is 2. Extending to multiples of 2 gives -6 to 6.
You could instead use an interval of 1 on both axes. That gives 12 squares vertically, which is still readable, and it keeps the picture undistorted. When the two axes can share one interval at a reasonable size, prefer that.
Reading between tick marks
Suppose the x-axis has gridlines every 100, and a point sits about a tenth of the way from the 300 line to the 400 line. Its x-coordinate is about 310. When a point falls between lines, estimate its position as a fraction of the interval and add that to the lower line. Points read this way are approximations, so state them as such unless the problem gives exact values.
Automating the choice
The procedure above is mechanical, so it can be written as code. This function takes the coordinates on one axis and returns the start, stop and step.
import math
def nice_step(span, target_intervals=8):
raw = span / target_intervals
magnitude = 10 ** math.floor(math.log10(raw))
for multiplier in (1, 2, 5, 10):
step = multiplier * magnitude
if step >= raw:
return step
def axis_range(values, target_intervals=8):
lo = min(min(values), 0)
hi = max(max(values), 0)
if lo == hi:
hi = lo + 1
step = nice_step(hi - lo, target_intervals)
start = math.floor(lo / step) * step
stop = math.ceil(hi / step) * step
return round(start, 10), round(stop, 10), step
small_x = [3, -4, -1, 2, 0]
small_y = [2, 5, -6, -3, 0]
print(axis_range(small_x))
print(axis_range(small_y))
large_x = [120, -250, 310]
large_y = [40, 90, -60]
print(axis_range(large_x))
print(axis_range(large_y))The output is:
(-4.0, 3.0, 1.0)
(-6, 6, 2)
(-300, 400, 100)
(-60, 100, 20)These match the hand calculation for the first two lines. The last line is worth checking by hand too. The y-values span -60 to 90, which is 150. The raw step is 18.75, which rounds up to 20. The range then extends to -60 and 100.
Two details in the code matter:
- Including 0 with
min(..., 0)andmax(..., 0)guarantees the axes cross inside the plot, even if all your points are in one quadrant. - The
lo == hicheck handles the case where every value on an axis is 0, which would otherwise make the span 0 and break the logarithm.
Equal scale versus unequal scale
Using different intervals on the two axes is fine, as long as you label them honestly. Using different drawn lengths per unit is a separate issue, and it changes the shape of the picture. If one unit along y is drawn shorter than one unit along x, a square looks like a wide rectangle, and angles and distances look wrong.
import matplotlib.pyplot as plt
xs = [0, 4, 4, 0, 0]
ys = [0, 0, 4, 4, 0]
fig, (left, right) = plt.subplots(1, 2, figsize=(8, 4))
for ax in (left, right):
ax.plot(xs, ys, marker="o")
ax.axhline(0, color="black")
ax.axvline(0, color="black")
ax.set_xlim(-1, 5)
ax.set_ylim(-1, 5)
ax.grid(True)
left.set_aspect("equal")
left.set_title("Equal drawn length per unit")
right.set_aspect(0.5)
right.set_title("y unit drawn half as tall")
plt.show()Both panels plot the same square with corners (0, 0), (4, 0), (4, 4) and (0, 4). Only the left panel looks like a square. When a task involves shapes, slopes, perpendicular lines or measured distances, keep the drawn length per unit the same on both axes. When you are graphing quantities with different units, such as seconds and meters, unequal drawn lengths are normal and expected.
Common errors
| Error | What goes wrong | Fix |
|---|---|---|
| Labeling the gridlines inconsistently (0, 1, 2, 4, 5) | Equal distances stand for unequal changes, so every point read afterward is wrong | Pick one interval and add it each time |
| Starting the axis at the lowest data value instead of 0 | The axes do not cross at the origin, so the quadrant of a point is hard to read | Always include 0 in both ranges |
| Labeling the squares instead of the lines | A point on a gridline gets read as lying in the middle of a square | Put each number on a tick mark or gridline, never between them |
| Choosing an interval of 1 for values in the hundreds | Most of the grid is empty, or the points fall off the page | Divide the span by the number of intervals you want and round up |
| Choosing a huge interval for small values | Points bunch together and cannot be told apart | Choose a smaller interval so the points spread over the grid |
| Forgetting that negative values need room too | Points with negative coordinates are cut off | Take the minimum as well as the maximum |
| Mixing up the intervals of the two axes when reading | You read x with y's scale and get the wrong coordinate | Check each axis's labels before reading each coordinate |
Edge cases
- All points in one quadrant. You can still include 0, but if the points are far from the origin, for example around (500, 520) to (540, 560), the plot will show a tiny cluster in one corner. In that case, you can start the axes at a higher value, but only if you mark clearly that the axes do not meet at (0, 0).
- Decimals and fractions. The same procedure works. For values between -0.35 and 0.4, the span is 0.75 and the step comes out as 0.1. Label the ticks with the same number of decimal places, such as 0.0, 0.1, 0.2, so the interval stays visible.
- Very different spans. If x spans 7 and y spans 700, you cannot use the same interval for both without losing the shape of one axis. Label the axes separately and note the difference.
- Fractions of an interval. Gridlines every 5 mean a point at 12 sits at 2 past the 10 line, which is two-fifths of the way to 15. Estimate and state it as an estimate.
Summary of the method
- Find the lowest and highest coordinate on one axis.
- Include 0.
- Divide the span by the number of intervals you want, usually about 8.
- Round the result up to 1, 2 or 5 times a power of 10.
- Extend both ends to multiples of that step.
- Label every tick evenly.
- Repeat for the other axis, then decide whether the drawn length per unit should match.
Exercise
The points are (-12, 30), (18, -45) and (0, 60). Choose a range and an interval for each axis, aiming for about 8 intervals, and state them.
Show answer
For x, the values run from -12 to 18, a span of 30. The raw step is 3.75, which rounds up to 5. Extending to multiples of 5 gives -15 to 20, with ticks every 5. For y, the values run from -45 to 60, a span of 105. The raw step is about 13, which rounds up to 20. Extending to multiples of 20 gives -60 to 60, with ticks every 20. The two axes use different intervals, which is acceptable because the points are not being used to measure shapes.
Exercise
The y-axis has gridlines every 20, labeled -60 to 60. A point sits exactly halfway between the 20 line and the 40 line. What is its y-coordinate, and why is an interval of 3 a poor choice for this axis?
Show answer
The y-coordinate is 30, the average of 20 and 40. An interval of 3 is a poor choice because it is awkward to count by, and halfway points and other fractions of an interval become hard to estimate. A step of 1, 2, 5, 10 or 20 times a power of ten keeps the arithmetic easy.