# restricting a pgfplots-based curve on a specified axis

I'm new to pgfplots and I'm having some trouble figuring out how to restrict a curve to a certain x-axis range. I've created a pgfplots based figure shown below

It is based on the following tex file:

\documentclass{standalone}
\usepackage{pgfplots}

% useful commands and definitions
\pgfplotsset{compat=1.10}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2 *sqrt(2*pi)) * exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
height=5cm, width=12cm,
no markers, domain=0:10, samples=100,
axis lines*=left,
ylabel=$y$,
ymax=0.45,
hide y axis,
every axis x label/.style={
at=(current axis.right of origin),
anchor=west
},
xlabel=$x$,
xtick={3,6.5},
xticklabels={$\mu_0$, $\mu_1$},
ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]

\node[above, red!50!black] at (axis cs:3,0.45) {Reference Value};
\node[above, red!50!black] at (axis cs:6.5,0.45) {Sensor Value};

\draw[thick,arrows={<->}] (axis cs:3,0.3) -- (axis cs:6.5,0.3)
node[pos=0.5,above] {Accuracy};

\draw[thick,arrows={<->}] (axis cs:4.9,0.1) -- (axis cs:8.1,0.1)
node[pos=0.5,below] {Precision};

\end{axis}
\end{tikzpicture}

\end{document}


The picture contains a x-axis range from (0,10), and has a blue normal density (gaussian) curve with a mean at tick point \mu_1 = 6.5. I would like to restrict gaussian curve from \mu_0 = 3 to 10, instead of having it rendered from (0,10).

I tried changing the statement making the gaussian curve from:

\addplot[very thick, cyan!50!black]{gauss(6.5,1)};


to:

\addplot[very thick, cyan!50!black, domain=3:10]{gauss(6.5,1)};


to achieve this effect, but now the figure looks like this:

The range of the x-axis is from (3,10), not (0,10). How do I make the picture look like:

I removed the blue line from (0,3), or (0,\mu_0), by hand using gimp here.

Use domain=3:10 in \addplot options and put xmin=0,xmax=10 in axis options.

\documentclass{standalone}
\usepackage{pgfplots}

% useful commands and definitions
\pgfplotsset{compat=1.10}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2 *sqrt(2*pi)) * exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
height=5cm, width=12cm,
no markers,  samples=100,
xmin=0,xmax=10,  %% <-------------------------
axis lines*=left,
ylabel=$y$,
ymax=0.45,
hide y axis,
every axis x label/.style={
at=(current axis.right of origin),
anchor=west
},
xlabel=$x$,
xtick={3,6.5},
xticklabels={$\mu_0$, $\mu_1$},
ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major
]

\node[above, red!50!black] at (axis cs:3,0.45) {Reference Value};
\node[above, red!50!black] at (axis cs:6.5,0.45) {Sensor Value};

\draw[thick,arrows={<->}] (axis cs:3,0.3) -- (axis cs:6.5,0.3)
node[pos=0.5,above] {Accuracy};

\draw[thick,arrows={<->}] (axis cs:4.9,0.1) -- (axis cs:8.1,0.1)
node[pos=0.5,below] {Precision};

\end{axis}
\end{tikzpicture}

\end{document}


• axis cs: is not needed anymore since certain version (I say “certain” because I'm not certain). – Manuel Feb 4 '15 at 0:08
• @Manuel From version 1.11 onwards it is not needed. But the OP has \pgfplotsset{compat=1.10} in his code meaning he may have that version where it is needed. So I left it :-) – user11232 Feb 4 '15 at 0:10
• Yes, the TeX installation that is available to me is a bit out of date, but it is good to know that 'axis cs' isn't needed in future versions. – indraniel Feb 4 '15 at 4:08
• @HarishKumar : Thanks! This solution works great for me. – indraniel Feb 4 '15 at 5:01
• @indraniel Glad it helped. Have a nice time TeXing :-) – user11232 Feb 4 '15 at 5:03