Module 4 · Beginner · Functions and graphs

Common function shapes and their graphs

The function shapes every data scientist should recognise: linear, quadratic, cubic, exponential, logarithmic, reciprocal, square root and sigmoid, with uses.

By theprogrammers team · · 8 min read

A doctor glances at an X-ray and recognises a fracture. A mechanic hears a noise and knows it's the brakes. Experts recognise patterns. In data science, one of the most useful patterns to recognise is the shape of a curve.

When you plot your data and see a curve bending upwards faster and faster, you should think "exponential, maybe try a log scale". When growth is fast at first and then levels off, "logarithmic". When the error falls and then rises again, "quadratic, there's a best point". Recognising the shape tells you which formula might describe it, which transformation might straighten it, and which model might fit it.

This lesson is a field guide to the eight shapes you'll meet most often: what each looks like, its formula, how it behaves, and where it shows up in real data and ML.

What you need first: plot mathematical functions with Python and slope and intercept.

Key terms

  • Growth rate: how quickly a function's output increases as its input increases.
  • Exponential: a function where the input is in the power, like 2ˣ.
  • Logarithm: the reverse of an exponential, answering "what power gives this number?".
  • Asymptote: a line a curve approaches but never reaches.
  • Saturation: when a curve levels off and stops growing.

The eight shapes at a glance

import numpy as np
import matplotlib.pyplot as plt

shapes = [
    ("Linear: y = 2x + 1", np.linspace(-3, 3, 200), lambda x: 2 * x + 1),
    ("Quadratic: y = x²", np.linspace(-3, 3, 200), lambda x: x ** 2),
    ("Cubic: y = x³", np.linspace(-2, 2, 200), lambda x: x ** 3),
    ("Exponential: y = 2ˣ", np.linspace(-3, 5, 200), lambda x: 2 ** x),
    ("Logarithmic: y = log₂(x)", np.linspace(0.05, 16, 300), np.log2),
    ("Reciprocal: y = 1/x", np.linspace(0.1, 5, 200), lambda x: 1 / x),
    ("Square root: y = √x", np.linspace(0, 16, 200), np.sqrt),
    ("Sigmoid: y = 1/(1 + e⁻ˣ)", np.linspace(-8, 8, 200), lambda x: 1 / (1 + np.exp(-x))),
]
fig, axes = plt.subplots(2, 4, figsize=(12, 5.5))
for ax, (title, xs, f) in zip(axes.flat, shapes):
    ax.plot(xs, f(xs), lw=2)
    ax.axhline(0, color="grey", lw=0.6)
    ax.axvline(0, color="grey", lw=0.6)
    ax.set_title(title, fontsize=9)
plt.tight_layout()
plt.show()
A grid of eight small charts: a straight rising line (linear), a U shape (quadratic), an S-like curve through the origin (cubic), a curve hugging zero then shooting up (exponential), a curve rising fast then flattening (logarithmic), a curve falling steeply then flattening towards zero (reciprocal), a curve rising quickly then more slowly from zero (square root), and an S-shaped curve from 0 to 1 (sigmoid).

1. Linear: y = mx + c

Shape: a straight line. Behaviour: changes by the same amount for every step in x.

  • Real examples: a taxi fare per km, hourly pay, cost of n items at a fixed price.
  • In ML: linear regression and the first step of most models.

Covered fully in slope and intercept.

2. Quadratic: y = ax² + bx + c

Shape: a U (or ∩ if a is negative), called a parabola. Behaviour: falls then rises (or the reverse), with a single turning point.

  • Real examples: a thrown ball's path, revenue against price, area against side length.
  • In ML: squared error is quadratic, which is why loss curves often look like a U with a best point at the bottom.

Covered fully in quadratic equations.

3. Cubic: y = x³

Shape: an S-like curve through the origin. Behaviour: keeps the sign of x (negatives stay negative) and can have two turning points, like x³ − 3x.

4. Exponential: y = 2ˣ

Shape: almost flat, then shooting upwards. Behaviour: multiplies by the same amount for every step in x. y = 2ˣ doubles with each step.

  • Real examples: compound interest, viral sharing, population growth, bacteria. See percentage change, where 10% yearly growth gave this shape.
  • Decay version, like y = 0.5ˣ: halves each step. Radioactive decay, a medicine leaving the body, a car's value.
  • In ML: learning-rate schedules that decay, and the e in the sigmoid.

5. Logarithmic: y = log(x)

Shape: rises steeply at first, then flattens, but never stops rising. Behaviour: the reverse of exponential. Each time x doubles, log₂(x) goes up by just 1.

  • Real examples: the Richter scale for earthquakes, decibels for sound, "diminishing returns" (the 10th hour of practice helps less than the 1st).
  • In data science: taking the log of skewed data like incomes or prices pulls in the huge values. You'll see why in the log scales lesson.

6. Reciprocal: y = 1/x

Shape: falls steeply, then flattens towards zero, never reaching it. Behaviour: doubling x halves y. This is inverse proportion.

  • Real examples: travel time against speed for a fixed distance, cost per person when a bill is split, price per unit for bulk orders.
  • In statistics: averages get more precise as the sample grows, with uncertainty shrinking like 1/√n.

7. Square root: y = √x

Shape: rises quickly at first, then more and more slowly. Behaviour: to double y, you need to quadruple x.

  • Real examples: the area of a square gives its side length; the distance a falling object covers relates to time through a square root.
  • In data science: the standard deviation is a square root, and a square-root transform tames skewed counts.

8. Sigmoid: y = 1/(1 + e⁻ˣ)

Shape: an S, flat near 0, rising through 0.5 at x = 0, then flat near 1. Behaviour: squeezes any number into the range 0 to 1. This is called saturation.

  • Real examples: adoption of a new technology (slow start, rapid growth, then everyone has it), learning a skill.
  • In ML: logistic regression uses it to turn any score into a probability.

Comparing growth: who wins in the long run?

Linear, quadratic, exponential and logarithmic functions all grow, but at very different speeds:

import math

print("x  x²  2^x  log2(x)")
for x in [1, 5, 10, 20]:
    print(x, x ** 2, 2 ** x, round(math.log2(x), 2))
x  x²  2^x  log2(x)
1 1 2 0.0
5 25 32 2.32
10 100 1024 3.32
20 400 1048576 4.32

At x = 20, the exponential is over a million, the quadratic 400, and the logarithm still under 5. In the long run:

logarithmic < linear < quadratic < exponential

This ranking is exactly what Big O notation uses to compare how algorithms slow down as data grows: an O(log n) search beats an O(n) one, which beats O(n²), and O(2ⁿ) is hopeless for large inputs.

How to identify a shape from data

Look at the differences and ratios between equally spaced values:

Pattern in the y valuesShapeExample
Same difference each stepLinear3, 5, 7, 9 (+2 each time)
Differences grow by the same amountQuadratic1, 4, 9, 16 (+3, +5, +7)
Same ratio each stepExponential3, 6, 12, 24 (×2 each time)
Rises by the same amount each time x doublesLogarithmicx = 1, 2, 4, 8 → y = 0, 1, 2, 3
Levels off at a ceilingSaturating (sigmoid, square root)10, 30, 45, 52, 55, 56
values = np.array([3, 6, 12, 24, 48])
print(np.diff(values))
print(values[1:] / values[:-1])
[ 3  6 12 24]
[2. 2. 2. 2.]

The differences keep growing, but the ratio is a constant 2: exponential.

Practice

  1. Which shape matches each? (a) A phone plan: ₹199 + ₹10 per GB (b) Bacteria doubling every hour (c) A rocket's height when thrown and falling back (d) A probability from a score.
Show the answer

(a) Linear (b) Exponential (c) Quadratic (d) Sigmoid

  1. The values 2, 5, 10, 17, 26 come from equally spaced x. Which shape?
Show the answer

Differences: 3, 5, 7, 9, which grow by 2 each time. Quadratic (they're x² + 1 for x = 1 to 5).

  1. The values 5, 15, 45, 135 come from equally spaced x. Which shape, and what's the next value?
Show the answer

Constant ratio of 3: exponential. Next is 405.

  1. Which grows fastest for large x: 100x, x², or 1.1ˣ?
Show the answer

1.1ˣ. Exponentials always eventually beat any polynomial, even with a small base. (It overtakes both x² and 100x at around x = 96 to 100.)

  1. Splitting a ₹1,200 bill among n friends: which shape is cost per person against n?
Show the answer

Reciprocal: cost = 1200/n. Doubling the friends halves each share.

Key takeaways

  • Linear adds the same amount each step; exponential multiplies by the same amount.
  • Quadratic is a U with one turning point; cubic is an S that keeps its sign.
  • Logarithmic and square-root curves rise quickly then slow down; reciprocal falls towards zero.
  • The sigmoid squeezes any value into 0 to 1.
  • In the long run: logarithmic < linear < quadratic < exponential.
  • Spot shapes in data with differences (linear, quadratic) and ratios (exponential).

Frequently asked questions

What is the difference between linear and exponential growth?

Linear growth adds the same amount each step (2, 4, 6, 8). Exponential growth multiplies by the same factor each step (2, 4, 8, 16), so it eventually becomes far larger.

What does a logarithmic curve look like?

It rises steeply for small x, then flattens, while still rising slowly forever. It increases by the same amount each time x is multiplied by the same factor.

Why is the sigmoid function used in machine learning?

Because it turns any number, however large or small, into a value between 0 and 1, which can be read as a probability. Logistic regression and some neural networks use it.

What to learn next

  1. Move and resize these shapes in shift, stretch and flip function graphs.
  2. Revisit plot mathematical functions with Python.