The article body for this language is not available yet; showing the other language.
Blog & updates系统梳理学术论文中 5 类高频图表(算法流程图、实验对比图、网络拓扑图、系统架构图、数据流图)的 LaTeX 绘制方法,配合 DrawFig 在线工具实现从描述到代码的一站式生成。
shapes.geometric 库,可以直接使用菱形(判断)、圆角矩形(开始/结束)、平行四边形(输入/输出)等标准流程图符号。
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\begin{tikzpicture}[
startstop/.style={rectangle, rounded corners, minimum width=2.5cm, minimum height=0.8cm, text centered, draw},
process/.style={rectangle, minimum width=2.5cm, minimum height=0.8cm, text centered, draw},
decision/.style={diamond, minimum width=2cm, minimum height=0.8cm, text centered, draw, aspect=2},
arrow/.style={thick, ->, >=Stealth}
]
\node (start) [startstop] {开始};
\node (init) [process, below=of start] {初始化参数};
\node (check) [decision, below=of init] {满足条件?};
\node (update) [process, below=of check] {更新状态};
\node (stop) [startstop, below=of update] {结束};
\draw[arrow] (start) -- (init);
\draw[arrow] (init) -- (check);
\draw[arrow] (check) -- node[right] {是} (update);
\draw[arrow] (check.west) -- ++(-1.5,0) |- node[above, near start] {否} (init.west);
\draw[arrow] (update) -- (stop);
\end{tikzpicture}
关键点在于用 style 预定义每种形状的样式,后续节点声明时只需引用样式名,代码更简洁、更易维护。
pgfplots 宏包绘制,它基于 TikZ 但专门面向数据可视化,语法更直观。
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=12pt,
xlabel={数据集},
ylabel={准确率 (\%)},
symbolic x coords={Cora, Citeseer, Pubmed, ogbn-arxiv},
xtick=data,
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=-1},
ymin=60, ymax=100,
nodes near coords,
nodes near coords align={vertical},
]
\addplot coordinates {(Cora,92.3) (Citeseer,88.7) (Pubmed,90.1) (ogbn-arxiv,85.4)};
\addplot coordinates {(Cora,85.1) (Citeseer,82.3) (Pubmed,84.6) (ogbn-arxiv,79.2)};
\legend{本文方法, 基线方法}
\end{axis}
\end{tikzpicture}
ybar 表示纵向柱状图,symbolic x coords 用字符串作为横轴标签,nodes near coords 在每根柱子上方显示数值——审稿人最爱看这种标注。
graphdrawing 库可以自动布局,但需要 LuaLaTeX 编译。如果不想切换编译器,手动指定坐标是最稳妥的方案。
\begin{tikzpicture}[
vertex/.style={circle, draw, minimum size=0.7cm, inner sep=0pt, font=\small},
edge/.style={thick},
node distance=2cm
]
\node[vertex, fill=blue!20] (v1) at (0,2) {$v_1$};
\node[vertex, fill=blue!20] (v2) at (2,2) {$v_2$};
\node[vertex, fill=red!20] (v3) at (1,0.5) {$v_3$};
\node[vertex] (v4) at (-1,0) {$v_4$};
\node[vertex] (v5) at (3,0) {$v_5$};
\draw[edge] (v1) -- (v2);
\draw[edge] (v2) -- (v3);
\draw[edge] (v1) -- (v4);
\draw[edge] (v3) -- (v5);
\draw[edge, dashed] (v4) -- (v5);
\draw[edge, bend left=25] (v1) to (v3);
\end{tikzpicture}
这里用 fill=blue!20 和 fill=red!20 给不同类别的节点着色,dashed 表示虚边,bend left=25 画弧线避免与直边重叠——这些都是论文配图中常用的视觉区分手段。
fit 和 backgrounds 库可以轻松画出带分组框的架构图。
\usetikzlibrary{fit, backgrounds, positioning}
\begin{tikzpicture}[
module/.style={rectangle, draw, rounded corners, minimum width=2.2cm, minimum height=0.8cm, text centered, fill=white},
arrow/.style={->, >=Stealth, thick}
]
\node[module, fill=green!15] (ui) {前端界面};
\node[module, fill=yellow!15, below=of ui] (api) {API 网关};
\node[module, fill=blue!15, below left=1cm and 0.5cm of api] (auth) {认证服务};
\node[module, fill=blue!15, below right=1cm and 0.5cm of api] (biz) {业务逻辑};
\node[module, fill=orange!15, below=1.5cm of api] (db) {数据库};
\draw[arrow] (ui) -- (api);
\draw[arrow] (api) -- (auth);
\draw[arrow] (api) -- (biz);
\draw[arrow] (auth) -- (db);
\draw[arrow] (biz) -- (db);
\begin{scope}[on background layer]
\node[fit=(auth)(biz), draw, dashed, rounded corners, fill=gray!5, inner sep=10pt, label=above:微服务层] {};
\end{scope}
\end{tikzpicture}
fit 库自动计算包围盒,backgrounds 库让分组框绘制在底层不影响前景内容。这种分层表达在系统论文中几乎是标配。
chains 库可以快速串联多个处理步骤。
\usetikzlibrary{chains, arrows.meta}
\begin{tikzpicture}[
box/.style={rectangle, draw, rounded corners, minimum width=1.8cm, minimum height=0.7cm, text centered, fill=#1},
box/.default={white},
arrow/.style={->, >=Stealth, thick}
]
\node[box=green!15] (raw) {原始数据};
\node[box=yellow!15, right=1cm of raw] (clean) {数据清洗};
\node[box=orange!15, right=1cm of clean](feat) {特征工程};
\node[box=blue!15, right=1cm of feat] (train) {模型训练};
\node[box=red!15, right=1cm of train](eval) {评估部署};
\draw[arrow] (raw) -- (clean);
\draw[arrow] (clean) -- (feat);
\draw[arrow] (feat) -- (train);
\draw[arrow] (train) -- (eval);
\end{tikzpicture}
每一步用不同颜色区分阶段,箭头方向即数据流向,信息密度高但阅读负担低。
\begin{figure} 环境中,编译即得矢量级配图。