使用graphviz来画图 [1]

配置文件修改:

# 通过配置开启graphviz插件
extensions = ['sphinx.ext.graphviz']

# 设置 graphviz_dot 路径
graphviz_dot = 'dot'
# 设置 graphviz_dot_args 的参数,这里默认了默认字体
# 过-G, -N, -E 来设置全局的 graph、node、edge 属性(注意是单引号)
graphviz_dot_args = ['-Gfontname=Georgia',
                     '-Nfontname=Georgia',
                     '-Efontname=Georgia']
# 输出格式,默认png,这里我用svg矢量图
graphviz_output_format = 'svg'

开始使用Graphviz:

.. graphviz::

  digraph abc{
      a;
      b;
      c;
      d;

      a -> b;
      b -> d;
      c -> d;
  }

or

.. graphviz:: external.dot
../../../_images/sphinx-docs-with-graphviz1.png

实例

测试一下你的graphviz能否支持好中文(在中文label的前面增加一个空白字符):

digraph idp_modules{
 fontname = "Microsoft YaHei";
 rankdir = TB;
 fontsize = 12;
 
 node [fontname = "Microsoft YaHei", fontsize = 12, shape = "record" ];
 edge [fontname = "Microsoft YaHei", fontsize = 12 ];
 
     subgraph cluster_sl{
         label=" IDP支持层";
         bgcolor="mintcream";
         node [shape="Mrecord", color="skyblue", style="filled"];
         network_mgr [label=" 网络管理器"];
         log_mgr [label=" 日志管理器"];
         module_mgr [label=" 模块管理器"];
         conf_mgr [label=" 配置管理器"];
         db_mgr [label=" 数据库管理器"];
     };
 
     subgraph cluster_md{
         label=" 可插拔模块集";
         bgcolor="lightcyan";
         node [color="chartreuse2", style="filled"];
         mod_dev [label=" 开发支持模块"];
         mod_dm [label=" 数据建模模块"];
         mod_dp [label=" 部署发布模块"];
     };
 
 mod_dp -> mod_dev [label="依赖..."];
 mod_dp -> mod_dm [label="依赖..."];
 mod_dp -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"];
 mod_dev -> mod_dm [label="依赖..."];
 mod_dev -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"];
 mod_dm -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"];
}

显示:

../../../_images/sphinx-docs-with-graphviz1.png
[1]https://www.chenyudong.com/archives/sphinx-docs-draw-graphic-with-graphviz.html