【发布时间】:2010-11-22 13:36:52
【问题描述】:
有没有什么方法可以从 GraphPlot 生成的图形(FullForm 或 InputForm)中抽象出 GraphPlot 应用于 VertexCoordinate 规则的顶点顺序?我不想使用 GraphUtilities 函数 VertexList。我也知道 GraphCoordinates,但是这两个函数都适用于图形,而不是 GraphPlot 的图形输出。
例如,
gr1 = {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 1};
gp1 = GraphPlot[gr1, Method -> "CircularEmbedding",
VertexLabeling -> True];
Last@(gp1 /. Graphics[Annotation[x___], ___] :> {x})
给出以下六个坐标对的列表:
VertexCoordinateRules -> {{2., 0.866025}, {1.5, 1.73205}, {0.5, 1.73205}, {0., 0.866025}, {0.5, 1.3469*10^-10}, {1.5, 0.}}
我怎么知道哪个规则适用于哪个顶点,我可以确定这是 和 VertexList[gr1] 给出的一样吗?
例如
Needs["GraphUtilities`"];
gr2 = SparseArray@
Map[# -> 1 &, EdgeList[{2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6}]];
VertexList[gr2]
给出 {1, 2, 3, 4, 5}
但是....
gp2 = GraphPlot[gr2, VertexLabeling -> True,
VertexCoordinateRules ->
Thread[VertexList[gr1] ->
Last@(gp1 /. Graphics[Annotation[x___], ___] :> {x})[[2]]]];
Last@(gp2 /. Graphics[Annotation[x___], ___] :> {x})
给出六个坐标集:
VertexCoordinateRules -> {{2., 0.866025}, {1.5, 1.73205}, {0.5, 1.73205}, {0., 0.866025}, {0.5, 1.3469*10^-10}, {1.5, 0.}}
例如,如何为 gr2 的 VertexCoordinateRules 抽象出正确的 VertexList?
(我知道我可以通过在生成 gr2 后获取 VertexList 来纠正问题,例如)
VertexList@
SparseArray[
Map[# -> 1 &, EdgeList[{2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6}]], {6, 6}]
{1、2、3、4、5、6}
但我需要的信息似乎出现在 GraphPlot 图形中:我怎样才能获得它?
(我将图形转换为邻接矩阵的原因是,正如 Wolfram 的 Carl Woll 所指出的,它允许我包含一个“孤儿”节点,如 gp2 中)
【问题讨论】:
-
顺便说一句,用边列表表示断开连接图的另一种方法是为每个节点设置 i->i 边。绘图期间可能需要 SelfLoopStyle->None
-
是的,这是真的!在我了解 Carl Woll 的方法之前,我曾经使用过它。我有时需要展示自循环并且(目前)更喜欢邻接矩阵方法。
-
我认为两者都有用——如果您正在检查图形或进行不改变顶点数量的修改,则邻接矩阵更方便,而当您需要执行诸如拆分之类的操作时,edgelist 会更好图形一分为二