The quickest fix is to add \pgfplotsset{compat=1.11}
to the preamble.
By default, the coordinates of normal TikZ drawing macros like \draw
do not correspond to axis units, when used inside an axis
environment. Starting with the compatibility setting of 1.11
though, pgfplots
changes the default, so coordinates do correspond to axis coordinates, and not those of the underlying tikzpicture
. (I think this is the cause at least, though I'm not completely certain.)
That said, I would personally rather change the code to use the \addplot
macro of pgfplots
instead of \draw plot
, i.e.
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45]
\begin{axis}[
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-3.9999999999999982,
xmax=3.979999999999998,
ymin=-2.9800000000000013,
ymax=2.9800000000000013,
xtick={-3.0,-2.0,...,3.0},
ytick={-2.0,-1.0,...,2.0}
]
\addplot [line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] (\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot [line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] (\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot [line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] (\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot[line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] (\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\end{axis}
\end{tikzpicture}
By the way, \usepackage{pgf,tikz,pgfplots}
is a bit redundant, pgfplots
loads tikz
which loads pgf
, so you really only need \usepackage{pgfplots}
.
Complete example and output:

\documentclass[10pt]{article}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
Modified code:
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45]
\begin{axis}[
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-3.9999999999999982,
xmax=3.979999999999998,
ymin=-2.9800000000000013,
ymax=2.9800000000000013,
xtick={-3.0,-2.0,...,3.0},
ytick={-2.0,-1.0,...,2.0}
]
\addplot [line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] (\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot [line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] (\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot [line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] (\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\addplot[line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] (\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\end{axis}
\end{tikzpicture}
With \texttt{compat=1.11}:
% in general you want this line in the preamble, I added it here just for the sake
% of the example, to show that the above code works without it
\pgfplotsset{compat=1.11}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\begin{axis}[
x=1.0cm,y=1.0cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-3.9999999999999982,
xmax=3.979999999999998,
ymin=-2.9800000000000013,
ymax=2.9800000000000013,
xtick={-3.0,-2.0,...,3.0},
ytick={-2.0,-1.0,...,2.0},]
\clip(-4.,-2.98) rectangle (3.98,2.98);
\draw[line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] plot(\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\draw[line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] plot(\x,{sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\draw[line width=0.8pt,smooth,samples=100,domain=6.920000002293365E-6:0.9999961013223213] plot(\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\draw[line width=0.8pt,smooth,samples=100,domain=2.000002653901591:3.979999999999998] plot(\x,{0-sqrt(((\x)*((\x)-1.0)*((\x)-2.0))/6.0)});
\end{axis}
\end{tikzpicture}
\end{document}
\clip
instruction.