如何使用Mathematica绘制经典状态图?

Nin*_*ing 20 drawing wolfram-mathematica state-diagram

Mathematica绘制这样的东西(由Graphviz创建)是否可行且实用:

在此输入图像描述

这是我能得到的最好的(但形状和风格并不令人满意):

在此输入图像描述

码:

GraphPlot[{{A -> C, "go"}, {C -> B, "gone"}, {C -> D, 
   "went"}, {C -> C, "loop"}}, VertexLabeling -> True, 
 DirectedEdges -> True]
Run Code Online (Sandbox Code Playgroud)

Mr.*_*ard 21

你可以用这样的东西做VertexRenderingFunction.

GraphPlot[{{A -> C, "go"}, {C -> B, "gone"}, {C -> D, "went"}, {C -> C, "loop"}}, 
 DirectedEdges -> True, 
 VertexRenderingFunction -> ({{White, Disk[#, 0.15]}, 
     AbsoluteThickness[2], Circle[#, 0.15], 
     If[MatchQ[#2, A | B], Circle[#, 0.12], {}], Text[#2, #]} &)]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


方法2015年2月更新

为了保持使用绘图工具以交互方式重新排列图形的能力(双击),必须GraphicsComplex使用索引而不是坐标来保持顶点图形的内部.我相信人们可以通过VertexRenderingFunction使用递增变量来实现这一点,但使用后处理这样做可能更容易实现.这适用于Mathematica的版本7和10 ,大概是8和9:

GraphPlot[
  {{A -> C, "go"}, {C -> B, "gone"}, {C -> D, "went"}, {C -> C, "loop"}},
  DirectedEdges -> True
] /.
 Tooltip[Point[n_Integer], label_] :>
   {{White, Disk[n, 0.15]},
    Black, AbsoluteThickness[2], Circle[n, 0.15], 
    If[MatchQ[label, A | B], Circle[n, 0.12], {}], Text[label, n]}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Sjo*_*ies 5

没有必要进行交互式放置,以便将你的顶点放在所需的位置,就像mr.Wizard在他的回答中所建议的那样.你可以用VertexCoordinateRules它:

GraphPlot[{{A -> C, "go"}, {C -> B, "gone"}, {C -> D, "went"}, {C -> C, "loop"}}, 
    DirectedEdges -> True, 
    VertexRenderingFunction -> 
          ({{White, Disk[#, 0.15]}, AbsoluteThickness[2], Circle[#, 0.15], 
           If[MatchQ[#2, A | B], Circle[#, 0.12], {}], Text[#2, #]} &),
    VertexCoordinateRules -> 
          {A -> {0, 0}, C -> {0.75, 0},B -> {1.5, 0.25}, D -> {1.5, -0.25}}
]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述