Mathematica基础——GraphPlot
1、比如下图,虽然代码里面显示,图应该是有向图,但结果却没有明确指定方向:
GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 8 -> 1, 8 -> 2, 8 -> 8}]
2、如果需要把图的方向画出来,需要用DirectedEdges->True来指定。
GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 8 -> 1, 8 -> 2, 8 -> 8},
DirectedEdges -> True]
DirectedEdges的意思是,有方向的边。
3、如果需要写出各顶点的标签,需要用VertexLabeling -> True来限制:
GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 8 -> 1, 8 -> 2, 8 -> 8}, DirectedEdges -> True, VertexLabeling -> True]
VertexLabeling的意思是,标注顶点。
4、用下面的代码,可以为某一条边加上标签:
GraphPlot[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 8 -> 1, 8 -> 2, {8 -> 8,"8到8"}},DirectedEdges -> True, VertexLabeling -> True]
5、Mathematica可以轻松地绘制出一个36阶的完全图,感觉有点密集:
GraphPlot[Table[1, {20}, {20}]]
6、所以,用EdgeRenderingFunction -> None取消边的绘制,只留下36个顶点:
GraphPlot[Table[1, {20}, {20}], EdgeRenderingFunction -> None]