Because gnuplot knows the error function (erf), you can use the raw gnuplot function of PGFPlots to do what you want. Because I don't know the truncated normal distribution function, I am not 100% sure the implementation is right, but at least it seems I can reproduce the given figure from the Wiki article you posted in the question (see below).
For more details on how the solution works, have a look at the comments in the code.
% used PGFPlots v1.14
% (inspired by Jake's answer given here
% <http://tex.stackexchange.com/a/340939/95441>)
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.3,
}
% create cycle lists that uses the style from OPs figure
% <https://upload.wikimedia.org/wikipedia/en/d/df/TnormPDF.png>
\pgfplotscreateplotcyclelist{line styles}{
black,solid\\
blue,dashed\\
red,dotted\\
orange,dashdotted\\
}
% define a command which stores all commands that are needed for every
% `raw gnuplot' call
\newcommand*\GnuplotDefs{
% set number of samples
set samples 50;
%
%%% from <https://en.wikipedia.org/wiki/Normal_distribution>
% cumulative distribution function (CDF) of normal distribution
cdfn(x,mu,sd) = 0.5 * ( 1 + erf( (x-mu)/sd/sqrt(2)) );
% probability density function (PDF) of normal distribution
pdfn(x,mu,sd) = 1/(sd*sqrt(2*pi)) * exp( -(x-mu)^2 / (2*sd^2) );
% PDF of a truncated normal distribution
tpdfn(x,mu,sd,a,b) = pdfn(x,mu,sd) / ( cdfn(b,mu,sd) - cdfn(a,mu,sd) );
}
\begin{document}
\begin{tikzpicture}
% define macros which are needed for the axis limits as well as for
% setting the domain of calculation
\pgfmathsetmacro{\xmin}{-10}
\pgfmathsetmacro{\xmax}{10}
\begin{axis}[
xmin=\xmin,
xmax=\xmax,
ymin=0,
ymax=0.23,
ytick distance=0.05,
enlargelimits=0.05,
no markers,
smooth,
% use the above created cycle list ...
cycle list name=line styles,
% ... and append the following style to all `\addplot' calls
every axis plot post/.append style={
very thick,
},
yticklabel style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
},
xlabel={x},
ylabel={probability density},
]
\addplot gnuplot [raw gnuplot] {
% first call all the "common" definitions
\GnuplotDefs
% and then create the data tables
% in GnuPlot `x` key is identical to PGFPlots `domain` key
plot [x=\xmin:\xmax] tpdfn(x,-8,2,-10,10);
};
\addplot gnuplot [raw gnuplot] {
\GnuplotDefs
plot [x=\xmin:\xmax] tpdfn(x,0,2,-10,10);
};
\addplot gnuplot [raw gnuplot] {
\GnuplotDefs
plot [x=\xmin:\xmax] tpdfn(x,9,10,-10,10);
};
\addplot gnuplot [raw gnuplot] {
\GnuplotDefs
plot [x=\xmin:\xmax] tpdfn(x,0,10,-10,10);
};
\end{axis}
\end{tikzpicture}
\end{document}

Edit: Thoughts about how the tpdfn really should be defined
Thinking again about the discussion (in the comments below the question) where the tpdfn function is defined and if it must be the same as pdfn I came to the conclusion that for pdfn the area under the curve is 1. Assuming that is the case also for tpdfn then my previous solution would be wrong in general.
Then it is a "combination" of restricting the calculation to the domain [a, b] and using the tpdfn function. To support this view I have added two more plots which can be created from the one given source below successively.
For the left image I (just) shifted the "black" curve to mu = 0 (which then is the gray dashed curve). If I am right then it now must be, the blue shaded area must be of the same size as the red shaded area, because that is exactly the part we "truncated" on the left side of the corresponding pdfn function.
Having a look at the areas that could be true.
For the right image I in addition to the left image I truncated also "the right side" of the pdfn function. Here also I think, that (the sum of) the blue areas could be of the same size as the red area.
Here again: For more details on how it works, have a look at the comments in the code.
% used PGFPlots v1.14
% (inspired by Jake's answer given here
% <http://tex.stackexchange.com/a/340939/95441>)
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{
pgfplots.fillbetween,
}
\pgfplotsset{
% use at least `compat' level 1.11 or above so you can avoid
% writing `axis cs:` in front of each (TikZ) coordinate
compat=1.11,
}
% create cycle lists that uses the style from OPs figure
% <https://upload.wikimedia.org/wikipedia/en/d/df/TnormPDF.png>
\pgfplotscreateplotcyclelist{line styles}{
black,solid\\
blue,dashed\\
}
% define a command which stores all commands that are needed for every
% `raw gnuplot' call
\newcommand*\GnuplotDefs{
% set number of samples
set samples 50;
%
%%% from <https://en.wikipedia.org/wiki/Normal_distribution>
% cumulative distribution function (CDF) of normal distribution
cdfn(x,mu,sd) = 0.5 * ( 1 + erf( (x-mu)/sd/sqrt(2)) );
% probability density function (PDF) of normal distribution
pdfn(x,mu,sd) = 1/(sd*sqrt(2*pi)) * exp( -(x-mu)^2 / (2*sd^2) );
% PDF of a truncated normal distribution
tpdfn(x,mu,sd,a,b) = pdfn(x,mu,sd) / ( cdfn(b,mu,sd) - cdfn(a,mu,sd) );
}
\begin{document}
\begin{tikzpicture}
% define macros which are needed for the axis limits as well as for
% setting the domain of calculation
\pgfmathsetmacro{\xmin}{-10}
\pgfmathsetmacro{\xmax}{10}
\begin{axis}[
xmin=\xmin,
xmax=\xmax,
ymin=0,
ytick distance=0.05,
enlargelimits=0.05,
no markers,
smooth,
% use the above created cycle list ...
cycle list name=line styles,
% ... and append the following style to all `\addplot' calls
every axis plot post/.append style={
very thick,
},
yticklabel style={
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=2,
},
xlabel={x},
ylabel={probability density},
% needed to draw the "red" area
set layers,
]
% (moved description of how it works to the next `\addplot' command)
\addplot gnuplot [raw gnuplot] {
\GnuplotDefs
a = \xmin; b = \xmax;
plot [x=a:b] tpdfn(x,-8,2,a,b);
};
\addplot+ [name path=blue] gnuplot [raw gnuplot] {
\GnuplotDefs
a = \xmin; b = \xmax;
plot [x=a:b] tpdfn(x,0,2,a,b);
};
% ---------------------------------------------------------------------
% the definition of the following `\addplot' command is the new
% recommended way to use the function
\addplot [
black!50,
dashed,
% phase the dash half of the line so the whole curve looks
% "smooth" when adding the second trailing path
% (comment the next line to see what it looks like if you
% don't do this phase shift)
dash phase=1.5pt,
] gnuplot [raw gnuplot] {
% first call all the "common" definitions
\GnuplotDefs
%%%% -----
%%%% comment these lines for demonstration 2
% define `a' and `b'
a = -2; b = \xmax;
% and then create the data tables using `a' and `b'
% in gnuplot `x` key is identical to PGFPlots `domain` key
plot [x=a:b] tpdfn(x,0,2,a,b);
%%%% -----
%%%% uncomment these lines for demonstration 2
%%% a = -2; b = 2;
%%% plot [x=a:b] tpdfn(x,0,2,a,b);
%%%% -----
}
% first end the current path from the last coordinate to
% "the end of the plotting domain" by going down to zero and
% then right to `\xmax'
|- (\xmax,0)
% then jump back to the first coordinate of the plot and add
% another "trailing path" from there again down to zero and then
% left to `\xmin'
(current plot begin) |- (\xmin,0)
% (that means that the probability function is zero outside
% of the domain [a, b])
;
% ---------------------------------------------------------------------
% because of (I think) numerical issues we have to
% plot the "red" area in this style and not simply by
% `\addplot fill between [of=blue and gray]'
% assuming the gray dashed line has the `name path` "gray
% (in fact one would also need a `clip path', but the
% real command would be a bit too long as a comment)
%
% first switch to the given layer
\pgfonlayer{pre main}
% fill the area under the *full* gray curve ...
\addplot [
draw=none,
fill=red!10,
] gnuplot [raw gnuplot] {
\GnuplotDefs
%%%% -----
a = -2; b = \xmax;
plot [x=a:\xmax] tpdfn(x,0,2,a,b);
%%%% -----
%%% a = -2; b = 2;
%%% plot [x=a:b] tpdfn(x,0,2,a,b);
%%%% -----
} \closedcycle;
% ... and then fill the area below the *full* blue curve
% so it looks like a "fill between" plot.
%
% Please note that I have used the (truncated, because I
% used as lower domain bound the value -2) `pdfn' function
% here which supports that for the blue curve `tpdfn = pdfn`.
\addplot [
draw=none,
fill=white,
] gnuplot [raw gnuplot] {
\GnuplotDefs
plot [x=-2:\xmax] pdfn(x,0,2);
} \closedcycle;
\endpgfonlayer
% create an invisible path at y origin ...
\path [name path=origin] (\xmin,0) -- (\xmax,0);
% ... and use that to produce the blue filled area
\addplot [
blue!10,
] fill between [
of=origin and blue,
soft clip={
domain=-8:-2,
},
];
%%%% -----
%%% \addplot [
%%% blue!10,
%%% ] fill between [
%%% of=origin and blue,
%%% soft clip={
%%% domain=2:8,
%%% },
%%% ];
%%%% -----
\end{axis}
\end{tikzpicture}
\end{document}

\phiand\cdfinstead ofphiandcdf. Moreover, it seems a bad idea to use(and)as delimiters, since they will not be checked for proper nesting. So, use\def\phi#1{...(or better,\newcommand\phi[1]{...), and use curly braces when supplying an argument to the function. Using\newcommandyou will notice that\phiis already in use, and you might even want to use the greek letter in the graph. – gernot Dec 01 '16 at 11:16domaincovers all the range where the probability is significantly higher than 0. This is the case for the blue line sotpdfn = pdfn. But when you change the limits, i.e.aandb, to lets say-3.5and3.5, you will see thattpdfn ≠ pdfn. – Stefan Pinnow Dec 01 '16 at 16:36muandsigmafor the black and blue line are identical, but the maximum of the black line is higher than the maximum of the blue line ... – Stefan Pinnow Dec 01 '16 at 16:39