# Line up extra y tick labels with extra y ticks

I am trying to line up the extra y tick labels on this graph with the dashed lines and can't figure it out. How can I do this?

Thank you.

\usepackage{pgfplots}
\begin{tikzpicture}
\begin{axis}[
standard,
axis lines=middle,
xlabel = $x$,
ylabel = {$y$},
xtick={\empty},
ytick={\empty},
extra x ticks={1,3},
extra x tick labels={$x_0$,$x_0+h$},
extra y ticks={1, sqrt(3), 1.5},
extra y tick labels={$f(x_0)$, $f(x_0+h)$, $f(x_0+h)+h'(x_0+h)$},
]
\addplot [
domain=0:4,
samples=100,
color=black,
]
{.5*x+.5};
\addplot [
domain=0:4,
samples=100,
color=black,
]
{sqrt(x)};
\addplot [dashed,
domain=0:4,
samples=2,
]
{1};
\addplot [dashed,
domain=0:4,
samples=2,
]
{sqrt(3)};
\addplot [dashed,
domain=0:4,
samples=2,
]
{2};
\end{axis}
\end{tikzpicture}


## 1 Answer

The values given to extra y ticks need to be numbers. You can't give sqrt(3) there. So we define a macro

\pgfmathsetmacro{\tmp}{sqrt(3)}


and use it.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\pgfmathsetmacro{\tmp}{sqrt(3)}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
%standard,      %%<--- ????
axis lines=middle,
xlabel = $x$,
ylabel = {$y$},
xtick={\empty},
ytick={\empty},
extra x ticks={1,3},
extra x tick labels={$x_0$,$x_0+h$},
extra y ticks={1, \tmp, 1.5},
extra y tick labels={$f(x_0)$, $f(x_0+h)$, $f(x_0+h)+h'(x_0+h)$},
]
\addplot [
domain=0:4,
samples=100,
color=black,
]
{.5*x+.5};
\addplot [
domain=0:4,
samples=100,
color=black,
]
{sqrt(x)};
\addplot [dashed,
domain=0:4,
samples=2,
]
{1};
\addplot [dashed,
domain=0:4,
samples=2,
]
{sqrt(3)};   %% or \tmp
\addplot [dashed,
domain=0:4,
samples=2,
]
{1.5};
\end{axis}
\end{tikzpicture}
\end{document}