# How to get this Gaussian Plot

I wanted to get this Gaussian plot with the boxes to the bottom of the axis like this:

Here is the code that I have so far:

\documentclass[11pt]{book}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
no markers,
domain=-6:6,
samples=100,
axis lines*=left,
xlabel=$x$,
ylabel=$G(x)$,
% every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=12cm,
%xtick=\empty,
%ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major,
]

\end{axis}
\end{tikzpicture}
\caption{Bell Shaped Gaussian Distribution}
\end{center}
\end{figure}

\end{document}


My first approach would be to draw the boxes manually:

\documentclass[11pt]{book}
\usepackage{pgfplots}
\usetikzlibrary{positioning,calc}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}[%
G node/.style={minimum width=1cm,align=center},%
]
\begin{axis}[
no markers,
domain=-6:6,
samples=100,
axis lines*=left,
xlabel=$x$,
ylabel=$G(x)$,
% every axis y label/.style={at=(current axis.above origin),anchor=south},
every axis x label/.style={at=(current axis.right of origin),anchor=west},
height=5cm, width=12cm,
%xtick=\empty,
%ytick=\empty,
enlargelimits=false, clip=false, axis on top,
grid = major,
]

\begin{scope}[yshift=-1cm] % shift boxes here
\node[G node,anchor=west] (L)  at (rel axis cs: 0,0) {$G(n)$};
\node[G node,anchor=east] (R)  at (rel axis cs: 1,0) {$G(n)$};
\node[G node]             (C)  at (rel axis cs: .5,0) {$G(0)$};
\node[G node,anchor=west] (CR) at (C.east) {$G(1)$};
\node[G node,anchor=east] (CL) at (C.west) {$G(1)$};
\node[] at ($(L)!.5!(CL)$) {$\dots$};
\node[] at ($(R)!.5!(CR)$) {$\dots$};
% draw lines
\draw (L.south west) rectangle (R.north east);
\draw (L.north east) -- (L.south east);
\draw (CL.north west) -- (CL.south west);
\draw (CL.north east) -- (CL.south east);
\draw (CR.north west) -- (CR.south west);
\draw (CR.north east) -- (CR.south east);
\draw (R.north west) -- (R.south west);
\end{scope}
\end{axis}

\end{tikzpicture}
\end{center}
\end{figure}
\end{document}


As Guilherme Z. Santos mentioned in the comments you can add the axis option xticklabel=\empty to remove the ticks on the x axis.

• I know it's not directly on the OP's question but, as the example image shows, there are no labels on x axis. So, maybe it's relevant to put in your answer the xticklabel=\empty? (not xtick to preserve thegrid) Sep 20, 2016 at 6:23
• The axis parameters are just a copy of OP's MWE. Sep 20, 2016 at 6:24
• I know. I was just suggesting so that both Images are equal. Sep 20, 2016 at 6:26