python画流程图库_Tikz 画流程图

本博客是由多个资料总结形成的,主要参考博客为https://www.jianshu.com/p/2d01d5eaaa77

Tikz 是 latex中的绘图工具

对于数学图形来说,最好还是使用python画图工具,Tikz适合画一下流程图,简单示意图

浮动体

为了更好的控制tikzpicture的位置,可以直接将绘制图像放到浮动体中。

\begin{figure}[!htp]

\begin{tikzpicture}[node distance=2cm]

\draw (0,0) circle (1ex)

\end{tikzpicture}

\end{figure}

tikzpicture 流程图

1.引入包

包为tikz

需要的库函数为arrows(控制箭头) shapes

\usepackage{tikz}

\usetikzlibrary{arrows,shapes,chains}

定义节点(node)

\tikzstyle{startstop} = [rectangle, rounded corners, minimum width = 2cm, minimum height=1cm,text centered, draw = black, fill = red!40]

\tikzstyle{process} = [rectangle, minimum width = 3cm, minimum height = 1cm, text centered, draw = black]

\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black]

解释

# 节点形状

rectangle:矩形,可加圆角(rounded corners)

trapezium:平行四边形

diamond:菱形

# 尺寸

minimum width

minimum height

# 文本

text centered:文本居中

# 文本宽度

text width=3cm:文本超过3cm时会自动换行

# 边框

draw

# 填充颜色

fill

定义箭头

\tikzstyle{ arrow1 } = [thick, ->, >= stealth]

解释:

# 线粗:

thick:粗

thin:细

# 箭头

->:反向箭头

:双向箭头

# 虚线

dashed

# 箭头形状

>=stealth

至此准备工作已经结束

tikz绘图——确定node位置

\node (start) [startstop] {Start};

解析

# name

(start):这个节点的name,后面需要用这个name调用这个节点。

# 属性

decision:需要调用的节点的属性

# 位置

below of=process1:定义节点的位置

left of:

right of:

# 偏移,对位置进行微调

yshift:

xshift:

# title

{Start}:结果显示的标题

tikz绘图——画箭头

\draw [arrow] (decision1) -- node[anchor=east] {yes} (process2a);

解析:

# 属性

[arrow]:需要调用的箭头的属性

(decision1):箭头的起始位置

(process2a):箭头的终止位置

# 线型

--:直线

|-:先竖线后横线

-|:向横线后竖线

# 文字:如果需要在箭头上添加文字

{yes}:需要添加的文字

# 文字的位置,上南下北左东右西(与地图方位不一致)

[anchor=east]:

[anchor=south]:

[anchor=west]:

[anchor=north]:

[anchor=center]:

tikzpicture

缩放图片大小:

\begin{tikzpicture}[scale=0.9]

也可以用xscale 和 yscale来指定

如果需要同时缩放字体和node可以紧接着加入下面这条

\tikzstyle{every node}=[font=\small,scale=0.9]

其中字体指定为小号,其他缩放参数类似

放缩样例

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{shapes,arrows}

\usetikzlibrary{fit,calc,positioning}

\begin{document}

\pagestyle{empty} % 无页眉页脚

\tikzstyle{startstop} = [rectangle,rounded corners, minimum width=3cm,minimum height=1cm,text centered, draw=black]

\tikzstyle{io} = [trapezium, trapezium left angle = 70,trapezium right angle=110,minimum width=3cm,minimum height=1cm,text centered,draw=black]

\tikzstyle{process} = [rectangle,minimum width=3cm,minimum height=1cm,text centered,text width =3cm,draw=black]

\tikzstyle{decision} = [diamond,minimum width=3cm,minimum height=1cm,text centered,draw=black]

\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{tikzpicture}[node distance = 2cm, scale = 0.6, transform shape]

% \tikzstyle{every node}=[scale=0.5]

\node (start) [startstop] {Start};

\node (input1) [io,below of=start] {Input};

\node (process1) [process,below of=input1] {Process 1};

\node (decision1) [decision,below of=process1,yshift=-0.5cm] {Decession 1};

\node (process2a) [process,below of=decision1,yshift=-0.5cm] {Process 2};

\node (process2b) [process,right of =decision1,xshift=2cm] {Process 2b};

\node (out1) [io,below of=process2a] {Output};

\node (stop) [startstop,below of=out1] {Stop};

\draw [arrow] (start) -- (input1);

\draw [arrow] (input1) -- (process1);

\draw [arrow] (process1) -- (decision1);

\draw [arrow] (decision1) -- node[anchor=east] {yes} (process2a);

\draw [arrow] (decision1) -- node[anchor=south] {no} (process2b);

\draw [arrow] (process2b) |- (process1);

\draw [arrow] (process2a) -- (out1);

\draw [arrow] (out1) -- (stop);

\end{tikzpicture}

\begin{tikzpicture}

\node[draw](A){A};

\node[right=3em of A,draw](B){B};

\node[left=3em of A,draw](C){C};

\node[above=3em of A,draw](D){D};

\node[below=3em of A,draw](E){E};

\node[fit=(A) (B) (C) (D) (E), draw]{};

\end{tikzpicture}

\begin{tikzpicture}[scale=0.5,transform shape]

\node[draw](A){A};

\node[right=3em of A,draw](B){B};

\node[left=3em of A,draw](C){C};

\node[above=3em of A,draw](D){D};

\node[below=3em of A,draw](E){E};

\node[fit=(A) (B) (C) (D) (E), transform shape=false,draw]{};

\end{tikzpicture}

\end{document}

参考博客

[1] https://www.jianshu.com/p/2d01d5eaaa77

[2] 文档

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值