LaTeX floats a figure for you as if it was a rotting raft in the middle of a stormy ocean. Most folks learn to tame this beast of burden, but I find that there are times when I need my figures to stay within the section, subsection, or subsubsection I references them in.
Using \FloatBarrier from the placeins package, you can force LaTeX to display all the figures that precede the \FloatBarrier command before displaying any of the content after the command.
You can add \FloatBarrier to the section, subsection, or subsubsection commands using the extraplaceins package that I modified to include subsection and subsubsections. Then add this to your LaTeX document:
Download it here: http://lexfridman.com/files/research/extraplaceins.sty