以《机器学习》第85页的图为例:
使用包:
\usepackage{tikz}
代码:
\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\thispagestyle{empty}
% 定义基本形状
\tikzstyle{results}=[ellipse ,text centered,draw=black]
\tikzstyle{decisions} =[rectangle, rounded corners,text centered, draw = black]
% 箭头形式
\tikzstyle{arrow} = [-,>=stealth]
\begin{tikzpicture}[node distance=1cm]
%定义具体形状和相关位置
\node[decisions](rootnode){ 纹理$=?$ };
\node[decisions,below of=rootnode,yshift=-0.5cm,xshift=-2cm](rhopoint){密度$\leq0.381?$};
\node[decisions,below of=rootnode,yshift=-0.5cm,xshift=0.5cm](touchpoint){触感$=?$};
\node[results,below of=rootnode,yshift=-0.5cm,xshift=2.5cm](result1){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=-1cm](result2){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=0.5cm](result3){好瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=2cm](result4){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=3.5cm](result5){好瓜};
%连接形状
\draw [arrow] (rootnode) -- node [left,font=\small] {清晰} (rhopoint);
\draw [arrow] (rootnode) -- node [right,font=\small] {稍糊} (touchpoint);
\draw [arrow] (rootnode) -- node [right,font=\small] {模糊} (result1);
\draw [arrow] (rhopoint) -- node [left,font=\small] {是} (result2);
\draw [arrow] (rhopoint) -- node [right,font=\small] {否} (result3);
\draw [arrow] (touchpoint) -- node [left,font=\small] {硬滑} (result4);
\draw [arrow] (touchpoint) -- node [right,font=\small] {软粘} (result5);
\end{tikzpicture}
\end{document}