1

How can I produce the following image with tikz?

enter image description here

I have seen the codes for plotting the normal curve, but how to get the rectangular shapes inscribed right at their centers? The red is not so important.

  • 1
    Search this site: http://pgfplots.sourceforge.net/gallery.html for "hist" – LaRiFaRi Jul 28 '15 at 13:51
  • 2
    I think you can do it yourself with http://tex.stackexchange.com/questions/160854/how-to-draw-density-estimate-on-histogram-by-pgfplots and then http://tex.stackexchange.com/questions/237085/histogram-with-overlaying-gauss-curve-pgfplots – percusse Jul 28 '15 at 14:09

1 Answers1

10

Annotate at your leisure...

\documentclass[tikz,border=5]{standalone}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,
  tick label style={font=\sansmath\sffamily},
  axis line style={draw=black!80, line width=0.1875ex},
  y tick label style={/pgf/number format/fixed},
  tick style={major tick length=0.0ex},
  major grid style={thick, dash pattern=on 0pt off 2pt, black!50},
}
\pgfmathdeclarefunction{norm}{3}{%
  \pgfmathparse{sqrt(0.5*#3/pi)*exp(-0.5*#3*(#1-#2)^2)}%
}
\begin{document}
\begin{tikzpicture}[line cap=round, line join=round]
\begin{axis}[ymajorgrids, xmajorgrids]
\addplot [ybar, domain=0:15, samples=16, fill=blue!50!cyan, draw=none] 
  (x, {norm(x, 7.5, 0.25)});
\addplot [very thick, draw=orange,  domain=0:15, samples=100, smooth]
  (x, {norm(x, 7.4, 0.25)});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437