Latex:绘图tikz

流程图

遗传算法流程图

\begin{figure}[htbp]
	\tikzstyle{startstop} = [rectangle, rounded corners,thick, minimum width=1cm, minimum height=0.5cm,text centered, draw=black, fill=white,text width=1cm]	% 定义开始结束
	\tikzstyle{process} = [rectangle,thick, minimum width=3cm, minimum height=0.5cm, text centered, draw=black, fill=white,text width=3cm]	% 定义步骤
	\tikzstyle{decision} = [diamond,aspect = 4, thick, minimum width=3cm, minimum height=0.5cm, text centered, draw=black, fill=white]	% 定义判断框
	\tikzstyle{arrow} = [thick,->,>=Latex]	% 定义箭头
	\centering
	\begin{tikzpicture}[node distance=1cm]
	% 定义流程图具体形状
	\node (start) [startstop] {开始};
	\node (pro1) [process, below of=start] {创建初始群};
	\node (pro2) [process, below of=pro1] {适应度计算};
	\node (dec1) [decision, below of=pro2,yshift=-0.38cm] {满足终止准则?};
	\node (pro3) [process, below of=dec1,yshift=-0.38cm] {选择操作};
	\node (pro4) [process, below of=pro3] {交叉操作};
	\node (pro5) [process, below of=pro4] {变异操作};
	\node (pro6) [process, right of=pro3,xshift=3cm] {变异操作};
	\node (stop) [startstop, below of=pro6] {结束};
	
	% 连接具体形状
	\draw [arrow](start) -- (pro1);
	\draw [arrow](pro1) -- (pro2);
	\draw [arrow](pro2) -- (dec1);
	\draw [arrow](dec1) -- (pro3);
	\draw [arrow](pro3) -- (pro4);
	\draw [arrow](pro4) -- (pro5);
	\draw [arrow](pro5) -| (-3,-2) |- (pro2);
	\draw [arrow](dec1) -| (pro6);
	\draw [arrow](pro6) -- (stop);
	
	\end{tikzpicture}
	\caption{遗传算法流程图}
	\label{fig:flowchart_ga}
\end{figure}

Latex:绘图tikz_第1张图片

数据结构图

队列

\begin{figure}[htbp]
	\centering
	\begin{tikzpicture}[>=Latex]

	\draw [thick,blue] (0,0)--(4,0);
	\draw [thick,blue] (0,0.8)--(4,0.8);
	\draw [thick,blue] (0,0)--(0,0.8);
	\draw [thick,blue] (0.8,0)--(0.8,0.8);
	\draw [thick,blue] (1.6,0)--(1.6,0.8);
	\draw [thick,blue] (2.4,0)--(2.4,0.8);
	\draw [thick,blue] (3.2,0)--(3.2,0.8);
	\draw [thick,blue] (4,0)--(4,0.8);
	
	\draw [thick,blue] (-1.2,0)--(-0.4,0) -- (-0.4,-0.8)--(-1.2,-0.8)--(-1.2,0);
	\draw [thick,blue] (4.4,0.8)--(5.2,0.8) -- (5.2,1.6)--(4.4,1.6)--(4.4,0.8);
	
	\node at (0.4,0.8)[above] {front};
	\node at (3.6,0.8)[above] {back};
	
	\draw[thick,blue,->] (0.4,0.4) arc (0: -90: 0.8);
	\draw[thick,blue,->] (4.8,1.2) arc (0: -90: 0.8);
	
	\node at (0,-0.5)[right] {Dequeue};
	\node at (4.4,0.3)[right] {Enqueue};
	

	\end{tikzpicture}
	\caption{队列示意图}
	\label{fig:queue}
\end{figure}

Latex:绘图tikz_第2张图片

\begin{figure}[htbp]
	\centering
	\begin{tikzpicture}[>=Latex]
	
	\draw [thick,blue] (0,0)--(4,0);
	\draw [thick,blue] (0,0.8)--(4,0.8);
	\draw [thick,blue] (0,0)--(0,0.8);
	\draw [thick,blue] (0.8,0)--(0.8,0.8);
	\draw [thick,blue] (1.6,0)--(1.6,0.8);
	\draw [thick,blue] (2.4,0)--(2.4,0.8);
	\draw [thick,blue] (3.2,0)--(3.2,0.8);
	\draw [thick,blue] (4,0)--(4,0.8);
	
	\draw [thick,blue] (4.4,0)--(5.2,0) -- (5.2,-0.8)--(4.4,-0.8)--(4.4,0);
	\draw [thick,blue] (4.4,0.8)--(5.2,0.8) -- (5.2,1.6)--(4.4,1.6)--(4.4,0.8);
	
	\node at (0.4,0.8)[above] {front};
	\node at (3.6,0.8)[above] {back};
	
	\draw[thick,blue,->] (3.6,0.4) arc (180: 270: 0.8);
	\draw[thick,blue,->] (4.8,1.2) arc (0: -90: 0.8);
	
	\node at (5.2,-0.4)[right] {Pop};
	\node at (5.2,1.2)[right] {Push};
	
	
	\end{tikzpicture}
	\caption{栈示意图}
	\label{fig:stack}
\end{figure}

Latex:绘图tikz_第3张图片

二叉树

先序遍历

\begin{figure}[htbp]
	\tikzstyle{treenode} = [circle,thick, minimum width=0.4cm, minimum height=0.4cm,text centered, draw=black, fill=white,text width=0.4cm]	% 定义树节点
	\tikzstyle{arrow} = [thick,->,>=Latex]		% 定义箭头线
	\centering
	\begin{tikzpicture}[node distance=1cm]
	% 绘制节点
	\node (F) [treenode] {F};
	\node (B) [treenode,below of=F,xshift = -1.6cm] {B};
	\node (G) [treenode,below of=F,xshift = 1.6cm] {G};
	\node (A) [treenode,below of=B,xshift = -1.2cm] {A};
	\node (D) [treenode,below of=B,xshift = 1.2cm] {D};
	\node (I) [treenode,below of=G,xshift = 1.2cm] {I};
	\node (C) [treenode,below of=D,xshift = -1cm] {C};
	\node (E) [treenode,below of=D,xshift = 1cm] {E};
	\node (H) [treenode,below of=I,xshift = -1cm] {H};
	
	% 绘制连线
	\draw [arrow] (F) -- (B);
	\draw [arrow] (F) -- (G);
	\draw [arrow] (B) -- (A);
	\draw [arrow] (B) -- (D);
	\draw [arrow] (G) -- (I);
	\draw [arrow] (D) -- (C);
	\draw [arrow] (D) -- (E);
	\draw [arrow] (I) -- (H);
	
	% 添加标注
	\node [below of=F,yshift=0.3cm,red]{1};
	\node [below of=B,yshift=0.3cm,red]{2};
	\node [below of=A,yshift=0.3cm,red]{3};
	\node [below of=D,yshift=0.3cm,red]{4};
	\node [below of=C,yshift=0.3cm,red]{5};
	\node [below of=E,yshift=0.3cm,red]{6};
	\node [below of=G,yshift=0.3cm,red]{7};
	\node [below of=I,yshift=0.3cm,red]{8};
	\node [below of=H,yshift=0.3cm,red]{9};
	\end{tikzpicture}
	\caption{前序遍历示意}
	\label{fig:preorder}
\end{figure}

Latex:绘图tikz_第4张图片

你可能感兴趣的:(Latex)