Graph Transformations
Once you know the graph of a basic function such as , or , you can draw a whole family of related graphs by shifting, stretching and reflecting it. These four moves explain what every constant in a formula like does to the picture.
The four moves
Start from . Changes outside the function act on the output (vertically); changes inside act on the input (horizontally), and they act "backwards".
| New function | Effect on the graph of |
|---|---|
| shift up by (down if ) | |
| shift right by (left if ) | |
| stretch vertically by (squash if ) | |
| squash horizontally by (stretch if ) | |
| reflect in the -axis (upside down) | |
| reflect in the -axis (left-right) |
Why "backwards" inside? The graph of reaches the value when , that is at . Every feature arrives 2 units later, so the graph moves right. In the same way reaches already at , so everything happens twice as fast and the graph is squashed toward the -axis.
Seeing it
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(-4, 6, 400)
def f(x):
return x**2
plt.figure(figsize=(6, 4))
plt.plot(xs, f(xs), label="x²", linewidth=2)
plt.plot(xs, f(xs - 2), label="(x − 2)² right 2")
plt.plot(xs, f(xs) + 3, label="x² + 3 up 3")
plt.plot(xs, 0.5 * f(xs), label="0.5·x² flatter")
plt.plot(xs, -f(xs + 1), label="−(x + 1)² left 1, flipped")
plt.ylim(-6, 10); plt.grid(alpha=0.3); plt.legend(fontsize=8)
plt.title("Transformations of y = x²")
for name, vx, vy in [("x²", 0, 0), ("(x − 2)²", 2, 0), ("x² + 3", 0, 3), ("−(x + 1)²", -1, 0)]:
print(f"{name:10} vertex at ({vx}, {vy})")x² vertex at (0, 0)
(x − 2)² vertex at (2, 0)
x² + 3 vertex at (0, 3)
−(x + 1)² vertex at (-1, 0)
Combining transformations
The general form
applies, in order: a horizontal squash by , a shift right by , a vertical stretch by (a flip if ), and a shift up by . A point on the graph of moves to:
Example. is stretched vertically by 2, moved right 1 and down 3. The vertex goes from to , and the point goes to .
def transform(point, a=1, b=1, h=0, k=0):
x0, y0 = point
return (x0 / b + h, a * y0 + k)
base = [(-1, 1), (0, 0), (1, 1), (2, 4)] # points on y = x²
for p in base:
q = transform(p, a=2, h=1, k=-3)
x, y = q
check = 2 * (x - 1)**2 - 3
print(f"{p} -> {q} on new curve: {abs(check - y) < 1e-12}")(-1, 1) -> (0.0, -1) on new curve: True
(0, 0) -> (1.0, -3) on new curve: True
(1, 1) -> (2.0, -1) on new curve: True
(2, 4) -> (3.0, 5) on new curve: True
Tip: To read a formula, rewrite the inside as . For that is : squash by 2, then shift right by 3, not by 6.
Transforming a sine wave
Trig functions use the same moves with special names:
| Constant | Name | Effect |
|---|---|---|
| amplitude | height of the wave above its midline | |
| period | length of one full cycle | |
| phase shift | horizontal shift | |
| vertical shift | midline |
oscillates between 1 and 7 (midline 4, amplitude 3), repeats every units and is shifted right by 1.
import numpy as np
xs = np.linspace(0, 10, 100001)
ys = 3 * np.sin(2 * (xs - 1)) + 4
print("min:", round(ys.min(), 4), " max:", round(ys.max(), 4))
print("period 2π/2 =", round(2 * np.pi / 2, 4))
print("y(1) =", 3 * np.sin(0) + 4, "(starts on the midline at the phase shift)")min: 1.0 max: 7.0
period 2π/2 = 3.1416
y(1) = 4.0 (starts on the midline at the phase shift)
In software
- UI animation and CSS:
transform: translate(…) scale(…)is exactly shifting and stretching. An easing curve on is reused for any duration and distance as : a horizontal stretch by and a vertical stretch by . - Audio: volume is amplitude (), pitch is frequency (), and a delay is a phase shift ().
- Data normalisation: shifts data by the mean and squashes it by the standard deviation before feeding it to a model.
- Graphics: model, view and projection matrices are combined shifts, scales and reflections in 2D and 3D (TRS).
Exercises
Exercise 1: Describe the moves
Describe how to get each graph from : (a) , (b) , (c) .
Answer
(a) left 4; (b) flip in the -axis, then up 2; (c) squash horizontally by a factor of 3.
Solution
- (a) , so : a shift of 4 to the left. The graph now starts at .
- (b) The minus sign outside reflects in the -axis, outside lifts it. It starts at and goes down.
- (c) A factor inside multiplies the input, so features arrive 3 times sooner: the point moves to .
Exercise 2: Move a point
The point lies on . Where does it go on ?
Answer
Solution
Check: at the new function gives .
Exercise 3: Write the formula
Write the equation of the parabola obtained by moving left 3, flipping it upside down and moving it up 5. Where is its vertex and where does it cross the -axis?
Answer
; vertex ; -intercept −4.
Solution
Exercise 4: Fit a sine wave
A day's temperature swings between 12 °C at 4 am and 26 °C at 4 pm, repeating every 24 hours. Write with in hours and check it in Python at and .
Answer
, giving 12 at and 26 at .
Solution
import math
def T(t):
return 7 * math.sin(math.pi / 12 * (t - 10)) + 19
print(round(T(4), 6), round(T(16), 6), round(T(10), 6))12.0 26.0 19.0
Test yourself
How is the graph of related to ?
- Shifted right 5
- Shifted up 5
- Shifted left 5
- Stretched by 5
What is the period of ?
- 3
- 4
Which formula reflects in the -axis?