# How to plot small function values in pgfplots?

I am trying to visualize two functions in pgfplots and I can't get my main message across that both end at the same point. How can I change this behaviour, preferably without additional external tools?

Here is my small example:

\documentclass[tikz]{standalone}

\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=0.0,
xmax=2,
ymin=0,
ymax=1.75,
axis x line=bottom,
axis y line=left,
xlabel=control parameter $r$,
ylabel=energy $(J)$,
ytick={}, yticklabels={},
xtick={1},
xticklabels={1},
restrict x to domain=0:2,
]

\addplot+[smooth,no marks, samples at={1.0,0.999,0.99,0.96,...,0.001,0}] {1.12*(1-x)^0.5};
\addplot+[smooth, densely dashed, no marks,samples=1000]{1.75*(1-x)^0.5};
\end{axis}
\end{tikzpicture}

\end{document}

With the following output:

Ideally both functions would end exactly at (1,0) but even with a high number of samples or explicitly giving the x value of 1.0 I can't get close. I tried using gnuplot alternatively but ran into the issue mentioned in Improve pfgplots precision with gnuplot, that pgfplots does not discard unbounded coordinates from gnuplot.

For an exponent of exactly 1/2 the sqrt function yields better results but only works in this special case.

Any ideas?

You can use sqrt function instead of raising zero to the power of 0.5.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0.0,
xmax=2,
ymin=0,
ymax=1.75,
axis x line=bottom,
axis y line=left,
xlabel=control parameter $r$,
ylabel=energy $(J)$,
ytick=\empty,
xtick={1},
xticklabels={1},
restrict x to domain=0:2,
]

\addplot+[smooth,no marks, samples at={1.0,0.999,0.99,0.96,...,0.001,0}] {1.12*sqrt(1-x)};
\addplot+[smooth, densely dashed, no marks,samples=1000]{1.75*sqrt(1-x)};
\end{axis}
\end{tikzpicture}

\end{document}

• Yes, that helps for the exponent of exactly 0.5. In my plots the exponent varies between 0.3 and 1 so that this only works in specific cases. – Alexander Apr 12 '13 at 12:33
• @Alexander Better include it in the question. For me \addplot+[no marks, domain=0:0.99999999,samples=500] gnuplot {1.12*(1-x)^0.3}; works without any problems. – percusse Apr 12 '13 at 12:50
• Thank you, the combination of domain and samples together solves the problem! – Alexander Apr 12 '13 at 12:57