I am new to latex. Actually i am using pre defined template for making graphs for my Advanced Algo Course.
Here is my code for drawing graph within a square.
\begin{figure}
\begin{tikzpicture}[scale=1.8, auto,swap]
% Draw a 7,11 network
% First we draw the vertices
\foreach \pos/\name in {{(3,2)/a}, {(2,1)/c}, {(3,1)/b},
{(4,1)/d},{(5,1)/e},{(1,0)/f},{(2,0)/g},{(6,0)/h}}
\node[vertex] (\name) at \pos {$\name$};
% Connect vertices with edges and draw weights
\foreach \source/ \dest /\weight/\pos in {c/a,
d/a,
b/a,
e/a,a/c,c/f,c/g,e/h}
\path[edge] (\source) -- (\dest);
\draw (0,-0.3) -- (6.4,-0.3) -- (6.4,1.8) -- (0,1.8) -- (0,-0.3);
\end{tikzpicture}
\end{figure}
\end{frame}
Problem:
First Image is where i want to place my graph. And second image is where my graph is being wrongly placed.

tikzpicturethen the picture would stay where you put it, the only reason to put something infigureis to allow latex to move it to help with page breaking, so it's working as designed but you could use\begin{figure}[htbp]to also allow it to tryh(here) – David Carlisle Oct 21 '16 at 06:43:)Usually is better use thefigurefloat because often the alternative is left ungraceful half-filled pages when an image does not fit at the end of the page. But you can change a bit the float's bevhaviour (see here) and use cross-references when is not posiblle place the figures whitin their section. – Fran Oct 21 '16 at 09:58