How to Make a Variation Table and Graph of ln(x) in TikZ
At a glance
- 1. Choose the function
Use the natural logarithm ln(x), whose domain is x greater than zero.
- 2. State its variation
Since its derivative is 1/x, ln(x) increases throughout its domain, from negative infinity to positive infinity.
- 3. Write the table
Show the endpoints 0+ and positive infinity, with an increasing arrow between the function values.
- 4. Plot the curve
Use PGFPlots, which builds on TikZ, to draw ln(x) over a positive x-range.
The natural logarithm, written , is defined only for . Its variation table is short: the function increases from to . The example below typesets that table and draws the graph using PGFPlots, a plotting package built on TikZ.
The code is a complete LaTeX document. Compile it with a current LaTeX distribution that includes PGFPlots.
Complete LaTeX example
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\[
\begin{array}{c|ccc}
x & 0^+ & & +\infty \\
\hline
\ln x & -\infty & \nearrow & +\infty
\end{array}
\]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=10cm,
height=7cm,
axis lines=middle,
xmin=0,
xmax=4,
ymin=-3,
ymax=2,
xlabel={$x$},
ylabel={$y$},
xtick={1,2,3,4},
ytick={-3,-2,-1,0,1,2},
grid=both,
domain=0.08:4,
samples=200,
unbounded coords=jump
]
\addplot[blue,thick] {ln(x)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
The only package needed for the graph is pgfplots; it loads TikZ as a dependency. The compat setting selects PGFPlots’ compatibility behavior. If your installation is older and does not support version 1.18, change the setting to a version available in that installation.
Why the table has this form
The domain of is . On that domain,
A positive derivative means the function is strictly increasing everywhere it is defined. The endpoint behavior is
In the array, the blank middle cell separates the two endpoint columns so the arrow can sit between them. The notation matters: the logarithm is not defined at zero, and the curve approaches the vertical axis without touching it.
How the graph settings work
The axis environment sets the visible window. Here, the horizontal range is from 0 to 4 and the vertical range is from to 2. The curve itself is drawn only for , because the logarithm cannot be evaluated at zero. The chosen lower plotting limit keeps the curve visible near the vertical axis; it does not change the function’s domain.
The expression {ln(x)} is PGFPlots’ natural-log function. With samples=200, PGFPlots evaluates it at many points and joins them to make a smooth curve. The curve passes through because , and through because . The axis lines=middle option places the horizontal axis at and the vertical axis at .
If you want to label the curve, add a node to the plot, for example:
\addplot[blue,thick] {ln(x)}
node[pos=0.7,above] {$y=\ln x$};
Put this in place of the original \addplot line. The pos value controls where along the plotted curve the label appears.
If you mean log base a
For , where and , the domain remains . If , the function increases, and its limits at the endpoints are and , just as for . If , it decreases instead: it tends to as and to as .
PGFPlots’ ln(x) draws the natural logarithm. To plot a logarithm with another base, use the change-of-base formula , so the plot expression becomes {ln(x)/ln(a)} with a numerical value substituted for a.
Common mistakes
- Plotting at : The logarithm is undefined there. Start the plotted domain at a small positive number instead.
- Using a decreasing arrow for : Its derivative is positive on its entire domain, so the variation arrow points upward as increases.
- Confusing the plot window with the domain: A graph shown only up to is still a graph of a function defined for every .
- Treating
logandlnas interchangeable in code: In PGFPlots, useln(x)for the natural logarithm. For a different base, apply the change-of-base formula. - Expecting the curve to cross the vertical axis: The line is an asymptote, not part of the logarithm’s graph.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.