Plotting · axes
Plot Axis Intercepts: Where Axes Cross and Intercept Points
The word intercept has two meanings in plotting, and mixing them causes confusion. In mathematics, an intercept is the point where a curve or surface meets a coordinate axis. In graphics, an axis intercept is the position along one axis at which another axis is drawn. This page treats both: how to compute the x-, y- and z-intercept of a function, and how to control where a plot places its axes. It is one of the plotting topics in Data and files.
Intercepts of a function
For a function of one variable, y = f(x), the y-intercept is the value f(0), and the x-intercepts are the solutions of f(x) = 0. For a line y = mx + b the y-intercept is b, and the x-intercept is −b/m when m is not zero. The line y = 2x − 6 has y-intercept −6 and x-intercept 3, since 2 × 3 − 6 = 0.
With two inputs the idea carries over. For a surface z = f(x, y), the z-intercept is the height above the origin, f(0, 0). The x-intercept is where the surface meets the x-axis, which needs both y = 0 and z = 0, so it is a solution of f(x, 0) = 0. The y-intercept is the solution of f(0, y) = 0.
A worked case: the plane z = 2x + 3y + 6.
- z-intercept: set x = y = 0, giving z = 6.
- x-intercept: set y = 0 and z = 0, so 2x + 6 = 0 and x = −3.
- y-intercept: set x = 0 and z = 0, so 3y + 6 = 0 and y = −2.
The three points (−3, 0, 0), (0, −2, 0) and (0, 0, 6) define the plane, which is why intercept form is a handy way to sketch one. Substitute back to confirm: 2 × (−3) + 6 = 0, 3 × (−2) + 6 = 0, and the third gives 6.
Finding intercepts numerically
When no formula is available, locate a sign change in sampled values and refine it. If f(a) and f(b) have opposite signs, a root lies between them, and linear interpolation gives a first estimate: x ≈ a − f(a) × (b − a) / (f(b) − f(a)). With f(1) = −2 and f(2) = 4, the estimate is 1 − (−2) × 1 / 6 = 1.333. Bisection or a secant step then tightens it. A root can be missed if the grid is coarser than the oscillations of the function, so sample finely near suspected crossings.
import numpy as np
x = np.linspace(-5, 5, 1001)
y = x**3 - 2*x + 1
s = np.where(np.sign(y[:-1]) != np.sign(y[1:]))[0]
roots = x[s] - y[s] * (x[s+1] - x[s]) / (y[s+1] - y[s])
Where the plot places its axes
Plotting tools offer two common layouts. In the boxed layout the axes sit along the left and bottom edges (and the box edges in 3D), crossing at the lower corner of the data range. In the crossed layout the axes are drawn through the origin, so negative values extend left of the vertical axis and below the horizontal one. Crossed axes suit functions such as sine or a parabola, where the origin has meaning. Boxed axes suit measured data where the origin is arbitrary or off the chart.
Setting an axis intercept means giving the coordinate on one axis where the other is drawn. Putting the x-axis at y = 0 gives the crossed look, while putting it at the minimum of y gives the boxed one. If the data range does not include the requested value, the axis is pushed to the nearest edge, so check that the axis lands where expected.
Marking an intercept point
To highlight an intercept on a figure, plot a single marker at the computed point and label its coordinates. For a 3D surface, a marker at (0, 0, f(0, 0)) with a short drop line to the base plane shows the z-intercept clearly. Choosing which levels to draw around it is covered under contour levels, and the combined surface and contour views appear under surface plots with contours.