Skip to main content
Graphs
This material has been adapted from material by Fergus Cooper and others from the "Essential Mathematics" module at the Doctoral Training Centre, University of Oxford.

This material has been adapted from material by Fergus Cooper and others from the "Essential Mathematics" module at the Doctoral Training Centre, University of Oxford.

Creative Commons License
This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

This course material was developed as part of UNIVERSE-HPC, which is funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

Creative Commons License

Graphs


YouTube lecture recording from October 2020

A recording of this lecture from October 2020; the material has changed a little since.
Youtube lecture thumbnail

Why graphs?

We often want to go between a formula and its graph, in either direction:
  • Given a formula, what shape will its graph have? This is called sketching.
  • Given some data, which formula describes them, and what are its parameters? We can often answer this by linearising the data.

Anatomy of a graph

Terminology:
  • YY or yy is the dependent variable, sometimes called the ordinate, marked on the vertical axis
  • XX or xx is the independent variable, sometimes called the abscissa, marked on the horizontal axis
  • The dependent variable is said to be graphed against the independent variable
Essential features:
  • Title
  • Axis labels (and units if appropriate)
Example graph with a title and axis labels

Equation of a straight line

Defined by a gradient, mm, and a yy-axis intercept, cc:
y=mx+cy = m x + c
Interpretation:
  • The intercept of this line on the yy axis is given by y=cy=c, since at x=0x=0, y=cy = c
  • The gradient of this line (also called its "slope") is given by
    m=y2−y1x2−x1m = \frac{y_2-y_1}{x_2 - x_1}
    ("change in yy divided by change in xx")
  • The gradient is also known as the rate of change of yy with respect to xx (more on this when we cover differentiation)
  • The intercept of this line on the xx axis is given by x=−c/mx = -c/m, since at y=0y=0 we must have mx=−cmx=-c
For example, the line y=12x+1y = \frac{1}{2}x + 1 has gradient m=1/2m = 1/2, yy intercept c=1c = 1 and xx intercept x=−c/m=−2x = -c/m = -2:
Graph of the line y = x/2 + 1, showing its intercepts and gradient

Sketching graphs

Given a formula, what shape is its graph? Polynomials are a good place to start.

Graphs of polynomials

An expression involving higher powers of xx is called a polynomial in xx:
y=anxn+an−1xn−1+an−2xn−2+…+a1x1+a0x0y = a_n x^n + a_{n-1} x^{n-1} + a_{n-2} x^{n-2}+\ldots+a_1 x^1 + a_0x^0
The highest power, nn, is its degree. The graph of a polynomial of degree nn has at most n−1n-1 bends (turning points) in it.

Sketching a polynomial

Consider
y=x5−5x3+4xy=x^5-5x^3+4x
  • To sketch this, we first find where y=0y=0. It factorises as
    y=x(x+1)(x−1)(x+2)(x−2)y = x(x+1)(x-1)(x+2)(x-2)
    so y=0y=0 at x=−2,−1,0,1,2x = -2, -1, 0, 1, 2
  • For large ∣x∣|x|, the x5x^5 term dominates, so yy rises to the right and falls to the left
    Here ∣x∣|x| is the absolute value (or modulus) of xx, its size ignoring its sign, so ∣−3∣=∣3∣=3|-3| = |3| = 3. So "large ∣x∣|x|" means xx far from zero, in either direction.
  • It has degree 5, so it has at most 4 bends, just enough to pass through all five zeros
  • Each zero comes from a single factor, so yy changes sign there
This is enough to sketch the graph. Plotting it in Python confirms the sketch:
Example graph of a polynomial

A checklist for sketching

To sketch the graph of a function:
  • Find where it is zero, positive and negative
  • Look at which terms dominate as x→±∞x\to\pm\infty
  • Look at the limit behaviour as xx approaches any points where the function is undefined (e.g. x→0x\to 0 for y=1/xy=1/x), which may give an asymptote
  • Work out how many bends it can have (more on this when we cover differentiation)
Then check your sketch by plotting the function in Python.

From data to a model

Now for the other direction. Given some data, which formula describes them, and what are its parameters?
  • It is hard to tell by eye whether a curve is quadratic, exponential or something else.
  • It is much easier to see whether points lie on a straight line, and a straight line is described by just two numbers, its gradient and intercept.
  • If we wish to test visually whether some data fit a particular relationship, we can transform the data to plot something which should be linear if the relationship holds.

Linearising: the recipe

  1. Write down the model, e.g. y=ax2+by = ax^2 + b.
  2. Rearrange it into the form Y=mX+cY = mX + c, where XX and YY depend only on the data, and mm and cc only on the parameters. Here Y=yY = y, X=x2X = x^2, m=am = a and c=bc = b.
  3. Plot YY against XX. If the points lie on a straight line, the data are consistent with the model. If they curve, the model is wrong.
  4. Read off the gradient and intercept, and work back to the parameters.

Example: is this quadratic?

There's a definite curve, and we may suspect the trend is quadratic: y=ax2+by = ax^2 + b.
Graph of data with nonlinear trend

Testing the model

If the parabolic relationship holds, plotting Y=yY=y against X=x2X=x^2 should result in a straight line. Plotting against xx or x3x^3 instead would leave the points on a curve.
Graph of data transformed to a linear trend

Gradient and intercept

We next add a trendline through these points which we can use to determine the gradient and intercept.
Graph of linear trend with trendline
  • We find (X,Y)(X,Y) lie along a straight line with slope 5 and YY-intercept 87.
  • This means that Y=5X+87Y=5X+87, so a=5a = 5 and b=87b = 87.
  • So, yy and xx can be modelled by the polynomial equation y=5x2+87y=5x^2+87.

Example: enzyme kinetics

The rate at which a given enzyme can catalyse a reaction can be dependent upon the substrate concentration. This is often modelled by the Michaelis-Menten equation:
V=Vmax⁡SKm+SV = \frac{V_{\max}S}{K_m + S}
where VV is the rate of the reaction, SS is the substrate concentration, Vmax⁡V_{\max} is the maximum rate, and KmK_m is the substrate concentration at which the rate is half its maximum.
First, plot the original data, which are observations of VV given varying SS:
Graph of original data

Straight-line form

Take the reciprocal of both sides:
1V=Km+SVmax⁡S=KmVmax⁡⋅1S+1Vmax⁡\frac{1}{V} = \frac{K_m + S}{V_{\max}S} = \frac{K_m}{V_{\max}}\cdot\frac{1}{S} + \frac{1}{V_{\max}}
  • We can derive a straight line graph from the above formula by plotting Y=1/VY=1/V against X=1/SX=1/S (this is called the Lineweaver-Burk plot)
  • It will have gradient m=Km/Vmax⁡m = K_m/V_{\max} and ordinate intercept c=1/Vmax⁡c = 1/V_{\max}

Transformed data

If the Michaelis-Menten model holds, plotting Y=1/VY=1/V against X=1/SX=1/S should result in a straight line.
Graph of linear trend

Gradient and intercept

We next add a trendline through these points which we can use to determine the gradient and intercept.
Graph of linear trend with trendline
  • We find (X,Y)(X,Y) lie along a straight line with slope 3 and YY-intercept 5.
  • This means that Y=3X+5Y=3X+5, so Vmax⁡=1/c=0.2V_{\max} = 1/c = 0.2 and Km=m/c=0.6K_m = m/c = 0.6.
  • So, VV and SS can be modelled by the equation V=0.2S/(0.6+S)V = 0.2S/(0.6+S).

Linearising in practice

  • Note, transforming the data also transforms any noise in it. Taking 1/V1/V magnifies the errors in small values of VV, and these points then have the most influence on the trendline.
  • In practice, it is usually better to fit the nonlinear model directly, e.g. using scipy.optimize.curve_fit.
  • Plotting in straight-line form is still a good way to check a model visually, and you will see these plots in many papers (e.g. Lineweaver-Burk, Arrhenius).
  • Logarithms, which we cover next, let us do the same for exponentials and power laws.

Introductory problems

For more practice, an AI tool can write new problems like the ones below. Ask it for problems of the same type and difficulty, or for problems set in your own field. For example, you could ask it to "write five ecology problems on straightening curved data into straight lines, at the level of these ones". Work them on paper first, then ask the tool to check your answers and to explain any step you are unsure of.

Introductory problems 1

Sketch the following graphs. First, use pen & paper, then use Python to check your answers. The notation after each equation indicates the range of values that the variable can take.
  1. y=3x+5x∈[0,10]y = 3x+5 \qquad\qquad x\in[0,10]
  2. y=x2/2−4x∈[−4,4]y = x^2/2 - 4 \qquad\qquad x\in[-4,4]
  3. y=xx∈[0,25]y = \sqrt{x} \qquad\qquad x\in[0,25]
  4. y=sin⁡(t)t∈[0,2π]y = \sin(t) \qquad\qquad t\in[0,2\pi]
  5. y=sin⁡(2t)t∈[0,2π]y = \sin(2t) \qquad\qquad t\in[0,2\pi]
  6. y=1/xx∈[0.1,5]y = 1/x \qquad\qquad x\in[0.1,5]
  7. y=−1/x2x∈[0.1,5]y = -1/x^2 \qquad\qquad x\in[0.1,5]
# hint import numpy as np from matplotlib import pyplot as plt x = np.linspace(0, 10, 100) y = 3 * x + 5 plt.plot(x, y)

Introductory problems 2

For which values of xx are the following functions positive? Negative? Zero?
  1. x2−9x^2 - 9
  2. sin⁡(x)\sin(x)
  3. sin⁡(3x)\sin(3x)
  4. 2/x−1/x22/x - 1/x^2

Introductory problems 3

A straight line passes through the points (1,3)(1, 3) and (4,9)(4, 9).
  1. What is its gradient?
  2. Write down its equation in the form y=mx+cy = mx + c.
  3. Where does it cross the yy axis? The xx axis?
  4. Does the point (−2,−3)(-2, -3) lie on the line?

Introductory problems 4

Use the checklist for sketching to sketch the graph of
y=x3−x2−6xy = x^3 - x^2 - 6x
Hint: start by factorising. Then use Python to check your sketch.

Main problems

Text relevant to these problems: Croft and Davison, 5th Edition, Chapters 17 & 18.

Main problems 1

The Lennard-Jones potential energy between two non-polar atoms may be given by the equation:
V(R)=AR12−BR6V(R)=\frac{A}{R^{12}} - \frac{B}{R^6}
where AA and BB are positive constants, V(R)V(R) is the potential energy, measured in Joules, and RR is the internuclear distance measured in A˚\AA.
  1. For which values of RR is V(R)V(R) positive? Negative? Zero?
  2. Sketch a graph (on paper) showing the potential energy between the two atoms as a function of RR given that A=1.6×10−14A=1.6\times 10^{-14} and B=1.0×10−17B = 1.0\times 10^{-17} (the values for argon).
  3. What is the potential energy between the two atoms at infinite separation?
  4. What would happen to the two atoms if they were brought very close together?
  5. What is the physical interpretation of the sign of V(R)V(R), and of its slope?
  6. What are the dimensions ([Length], [Mass], [Time]) and units of the constants AA and BB?
  7. Use Python to plot the graph of VV versus RR for A=1.6×10−14A=1.6\times 10^{-14} and B=1.0×10−17B = 1.0\times 10^{-17}. Remember to add relevant axis labels. Plot on the same graph the line of V=0V = 0, so you can verify your answers to 1. and 2. Choose the limits of your plot with care.

Main problems 2

How should these equations be rearranged to allow the plotting of a suitable linear graph, assuming that the constant parameters aa and bb are unknown, and we wish to use the graph to find them? Write down expressions for the gradient, XX-intercept and YY-intercept of each rearranged equation:
  1. y=a/xy = a/x
  2. y=b−axy = b - a \sqrt{x}
  3. y=b/(1+ax)y = b/(1+ax)

Main problems 3

The osmotic pressure of a solution of a protein is related to the concentration of that protein by the equation:
Z=RTbZ = RTb
where ZZ is the osmotic pressure in kPa, TT is the temperature in Kelvin, RR is the gas constant (R=8.314 kPa⋅dm3⋅mol−1⋅K−1R=8.314\,\text{kPa}\cdot\text{dm}^3\cdot\text{mol}^{-1}\cdot\text{K}^{-1}) and bb is the molarity of the protein (mol. solute per dm3^3 solution). Plot a suitable graph to determine, as accurately as possible, the molecular mass (take care with units!) of the protein given the following data taken at room temperature (usually taken as 21∘^{\circ}C):
Protein concentration (in g dm−3^{-3})7.318.427.642.157.4
Osmotic pressure (in kPa)0.2110.5330.8041.2361.701
Hint: compare the function with the equation of a straight line, y=mx+cy=mx+c, and think about the relationship between concentration, molar concentration and molecular weight.
Use Python to plot the graph and confirm your pen & paper solution.

Extension problems

Extension problems 1

The rate at which a given enzyme catalyses a reaction is dependent upon the substrate concentration:
V=Sm+cSV = \frac{S}{m+cS}
where VV is the rate of the reaction, SS is the substrate concentration and mm and cc are unknown constants.
  1. How can we transform VV and SS to derive a straight line graph relating them? What will be the gradient and the ordinate intercepts?
  2. There is more than one way to do this. Show that plotting S/VS/V against SS also gives a straight line, and find its gradient and intercepts.