Skip to content
ihateDesmos

Why graphing calculators draw fake vertical lines

· 8 min read · ihateDesmos

Graph tan x on many calculators and you will see near-vertical lines at the asymptotes. They are not part of the function. They are a side effect of how plotting works, and understanding why they appear explains a whole family of graphing errors.

The symptom

The function tan x is undefined at x = ±π/2, ±3π/2 and so on, where cos x = 0. Its graph is a row of separate branches, each rising from −∞ to +∞ between two asymptotes. Yet a simple plotter shows something else: the branches joined by steep lines that run the full height of the screen.

−6−4−2246−220
tan x, sampled at 91 evenly spaced points and joined with straight lines. The near-vertical lines bridge the asymptotes.

The same thing happens with 1/x at x = 0, with sec x and cot x, with rational functions such as 1/(x² − 4), and with step functions like floor x, where the “vertical lines” join the steps.

How a basic plotter works

A computer cannot draw a function at every real number, so it draws it at some of them. The simplest method picks evenly spaced x-values across the window (say one per pixel column), computes f(x) at each, and joins consecutive points with straight segments. For smooth functions this works well: at screen resolution, a curve is indistinguishable from a polyline with enough points.

The method has a hidden assumption: that the function is continuous between any two neighbouring samples, so a straight segment is a fair stand-in for what happens in between. Near an asymptote that assumption is false. One sample lands just left of π/2, where tan x is large and positive; the next lands just right, where it is large and negative. Joining them draws a line straight down through a gap where the function has no value at all.

Why more samples don’t fix it

The natural fix is to sample more densely. That makes the fake line steeper and thinner, but it is still there, because however close the last sample before the asymptote and the first after it are, there is always a pair on opposite sides. For a jump discontinuity such as floor x the problem is the same: two samples on either side of an integer get joined by a vertical segment.

Dense sampling has a second cost. Most of the curve is smooth and needs only a few points; the trouble is concentrated in tiny regions. Sampling everything finely wastes effort where it is not needed and still fails where it is.

Adaptive sampling: refine where it matters

A better approach decides where to sample based on what the function is doing. Start with a coarse set of points. For each pair of neighbours, look at the midpoint between them:

  • If the midpoint lies within half a pixel of the straight line joining its neighbours, the segment is a faithful picture of the curve there. Stop.
  • Otherwise, split the interval in two and repeat on each half.

This concentrates points where the curve bends sharply and uses few where it is nearly straight. It also gives a way to recognise trouble. Near an asymptote, splitting an interval never makes the segments behave: the function values on either side of the gap keep growing apart as the interval shrinks, instead of converging. When an interval narrower than a pixel still contains a jump bigger than the screen, it is treated as a break, and the curve is not joined across it.

−6−4−2246−220
Open in calculator
The same function with adaptive sampling. Each branch is drawn separately, and the asymptotes are left as gaps.

That is how the calculator on this site draws every explicit curve: points are refined until neighbouring samples are within half a pixel, and a jump that survives refinement to below a pixel is treated as a discontinuity. Jumps in step functions are handled the same way.

−4−224−220
Open in calculator
A step function and a rational function with two asymptotes, both drawn without connecting lines.

The opposite error: missing features

Joining dots can also hide things. A function that oscillates faster than the sample spacing is aliased: the plotter draws a slow wave, or a strange pattern, that has nothing to do with the real function. sin(50x) sampled at 200 points across a wide window is a good example.

−55−550
sin(50x) at 201 evenly spaced samples. The jagged pattern is aliasing: the samples are too far apart to follow the wave.
−55−550
Open in calculator
The same function with adaptive sampling: a solid band, because there are about 160 complete waves across the screen, many per pixel.

Adaptive sampling notices that the midpoints disagree with the straight segments and keeps refining, so the rapid oscillation is drawn honestly, as the dense band it really is at this zoom. Zoom in and the individual waves appear.

The hardest case of all is a feature thinner than any sample spacing that leaves no trace in the midpoints, such as a curve that touches the x-axis without crossing it. No amount of sampling can guarantee to find those. That needs a different idea: interval arithmetic, which reasons about whole ranges of x at once rather than individual points.

What you can do on any calculator

  • Know the function. If you expect an asymptote at x = a, a vertical line there is an artefact, not a crossing.
  • Change the window. Fake lines often appear or vanish when the window changes slightly, because the samples land in different places. Real features don’t.
  • Use dot mode. On TI calculators, dot mode plots the samples without joining them, which removes the false lines at the cost of a dotted curve.
  • Zoom in. A suspicious feature that is real will still be there at higher zoom.

In the calculator here you can type y = tan(x) and zoom anywhere: the asymptotes stay clean at every scale, and selecting the curve marks its roots exactly.

Read next

See it for yourself

Every figure in this post opens in the calculator, where you can change it and watch what happens.

Open the calculator