# Why can't I plot (x+2)^{1/3} properly using pgfplots? [duplicate]

I'm using the code

\documentclass{book}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=-5,
xmax=5,
ymin=-5,
ymax=5,
axis x line=middle,
axis y line=middle,
samples=100,
domain=-5:5,
]
\end{axis}
\end{tikzpicture}

\end{document}


to plot y= (x+2)^{1/3} which gives me this graph:

but it is not complete, because the right graph is:

How can I plot it like the second screenshot?

• – DJP
Jun 4, 2015 at 21:18
• f(x) is not real for x<2, because (x+2)^(1/3)=exp(1/3*ln(x+2)) and ln(x) is only defined for x>0. You'll get the complete graph (on the real part) with domain=-2:5. Jun 4, 2015 at 21:34
• You might also want to check wolframalpha. Jun 4, 2015 at 21:36
• @djp: Thanks for your links, but I couldn't solve my problem. Jun 4, 2015 at 21:37
• From the code given in the second link, modify to (x+2)/abs(x+2)*abs(x+2)^(1/3) and the graph gets shifted as you asked.
– DJP
Jun 4, 2015 at 21:45