How to Plot a Parametric Curve in PGFPlots
At a glance
- 1. Set the parameter range
Choose the interval of parameter values to sample with the domain option.
- 2. Write both coordinates
Use a parenthesized pair: the first expression gives x and the second gives y.
- 3. Set enough samples
Increase samples to make curved lines look smooth.
- 4. Check angle units
PGF math trigonometric functions use degrees, so convert radian parameters with deg().
Title: How to Plot a Parametric Curve in PGFPlots Category: latex
---- ARTICLE BODY ----
PGFPlots can draw a two-dimensional parametric curve directly; you do not need to convert it to an explicit equation such as . Give \addplot a range for the parameter and a pair of coordinate expressions. PGFPlots samples the parameter across that range and connects the resulting points.
The essential form is \addplot[domain=a:b] ({f(x)},{g(x)});. In this syntax, the plotting variable x is the parameter, while the two expressions inside the coordinate pair determine the plotted horizontal and vertical coordinates.
A complete example: a unit circle
This standalone document plots the circle , for :
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal image,
axis lines=middle,
xmin=-1.2, xmax=1.2,
ymin=-1.2, ymax=1.2,
xlabel={$X$},
ylabel={$Y$},
]
\addplot[
domain=0:6.2831853,
samples=201,
thick,
blue,
] ({cos(deg(x))}, {sin(deg(x))});
\end{axis}
\end{tikzpicture}
\end{document}
The required package is pgfplots. The domain option sets the parameter interval, and samples controls how many points PGFPlots evaluates. Here the domain is approximately to , in radians. PGF math’s sin and cos functions expect degrees, so deg(x) converts each sampled radian value before evaluating them. axis equal image gives the horizontal and vertical axes the same scale, so the circle does not appear stretched.
The symbols and in the mathematical description are the curve’s coordinates. The x inside the PGFPlots expressions is the parameter being varied; it is not the plotted horizontal coordinate unless you explicitly make it so.
Adapting the expressions
For a parametric curve and , put the two coordinate formulas in order:
\addplot[domain=a:b, samples=200] ({f(x)}, {g(x)});
For example, the curve , over can be written as:
\addplot[domain=-2:2, samples=200] ({x^2-1}, {x*(x^2-1)});
The first expression is always the horizontal coordinate and the second is the vertical coordinate. The parameter does not have to be called in your mathematical notation: in the usual PGFPlots expression syntax, x serves as its computational variable.
If your parameter is in degrees, use cos(x) and sin(x) directly. If it is in radians, convert it with deg(x), as in the circle example. This distinction matters for trigonometric functions, but not for polynomial expressions.
Sampling and plot appearance
PGFPlots approximates the curve with finitely many evaluated points. Increase samples when the curve has tight bends, oscillates rapidly, or looks polygonal. A larger number can take longer to compile, so start with a moderate value and raise it only as needed. Make sure the parameter interval covers the part of the curve you want to see; axis limits can also clip points outside the displayed region.
The order of the parameter values determines the order in which the points are connected. Reversing the domain can therefore reverse the direction of tracing. For a closed curve, the endpoints of the parameter interval should produce the same point if you want the line to join back to its start.
Common mistakes
- Writing two separate plots instead of a coordinate pair. A parametric plot needs both coordinates together, as
({first expression},{second expression}). - Using radians directly in
sinorcos. PGF math interprets their inputs as degrees. Usedeg(x)for a parameter in radians. - Using too few samples. Sparse sampling can make a smooth curve look like a series of straight segments.
- Confusing a parametric curve with a 3D plot. A two-dimensional parametric curve still has two coordinates, and . A three-dimensional parametric curve needs three coordinates and a 3D axis.
- Expecting equal units from a square-looking axis box. The box shape alone does not guarantee equal coordinate scales; use
axis equal imagewhen geometric proportions matter.
For additional \addplot options and coordinate-expression details, see the PGFPlots manual.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.