# Pgfplots ignoring domain

I'm trying to use pgfplots to plot -3ln(x-2):

\documentclass[border=10pt]{standalone}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{pgfplots}

\pgfplotsset{mystyle2/.style={
width=12cm,
height=12cm,
xmin=0,xmax=15,
ymin=-10,ymax=10}}

\begin{document}

\begin{tikzpicture}
\begin{axis}[mystyle2,
xlabel=$x$,
ylabel={$g(x) = -3ln(x-2)$}
]
domain=2:15,
y domain=-10:30
]
{(-3)*ln(x-2)};
\end{axis}
\end{tikzpicture}

\end{document}


I'd like to display the function up until y=10, however it seems to cut off at y=2. Why is this happening?

• try changing your x domain from 2:15 to something like 2.2:15. – Willie Wong Jul 20 '16 at 1:52
• @WillieWong That did it (although I used 2.02). I guess it tries to calculate x=2 and craps out. Thank you! – Mansfield Jul 20 '16 at 1:54

I ended up taking Willie Wong's advice and used a domain of 2.02:15. It seems that since (-3)ln(x-2) is undefined for x=2 it doesn't try a different point that would display the graph appropriately.
• I don't see why you think it would (try a different point). I mean, it evaluates the function where you've told it to, and it gets a NaN for x=2, so it does display the graph appropriately according to your specifications. By the way, you're also affected by the fact that pgfplots uses just 25 sample points by default, so the first point is calculated for x = 2, the next one for 2.54, and so on. A larger number of samples (e.g. samples=400) would also give you what you're after. – Torbjørn T. Jul 21 '16 at 18:01