更改 GraphPlot 中的边路线以避免歧义
我有以下无向图
gr={1->2,1->3,1->6,1->7,2->4,3->4,4->5,5->6,5->7};
,我希望用 GraphPlot 以“钻石”格式绘制它。我按照概述执行此操作 下面(方法 1)给出以下内容:
问题在于这种表示具有欺骗性,因为两者之间没有边缘顶点 4 & 1, 或 1 & 5(边缘是从 4 到 5)。我希望更改边缘 {4,5} 的路线以获得如下所示的内容:
我这样做的方法是包括另一条边 {5,4},现在我可以使用 MultiedgeStyle 来“移动”有问题的边,然后通过定义 EdgeRenderingFunction 来删除添加的边,从而不显示有问题的线。 (方法 2,“解决方法”)。至少可以说,这很尴尬。有更好的办法吗? (这是我的第一个问题!)
方法1
gr={1->2,1->3,1->6,1->7,2->4,3->4,4->5,5->6,5->7};
vcr={1-> {2,0},2-> {1,1},3-> {1,-1},4-> {0,0},5-> {4,0},6-> {3,1},7-> {3,-1}};
GraphPlot[gr,VertexLabeling-> True,
DirectedEdges-> False,
VertexCoordinateRules-> vcr,
ImageSize-> 250]
方法2(解决方法)
erf= (If[MemberQ[{{5,4}},#2],
{ },
{Blue,Line[#1]}
]&);
gp[1] =
GraphPlot[
Join[{5->4},gr],
VertexLabeling->True,
DirectedEdges->False,
VertexCoordinateRules->vcr,
EdgeRenderingFunction->erf,
MultiedgeStyle->.8,
ImageSize->250
]
I have the following undirected graph
gr={1->2,1->3,1->6,1->7,2->4,3->4,4->5,5->6,5->7};
which I wish to plot with GraphPlot in a 'diamond' format. I do this as outlined
below (Method 1) giving the following:
The problem is that this representation is deceptive, as there is no edge between vertices 4 & 1, or 1 & 5 (the edge is from 4 to 5). I wish to change the route of edge {4,5} to get something like the following:
I do this by including another edge, {5,4}, and I can now use MultiedgeStyle to 'move' the offending edge, and I then get rid of the added edge by defining an EdgeRenderingFunction, thus not showing the offending line. (Method 2,'Workaround'). This is awkward, to say the least. Is there a better way? (This is my first question!)
Method 1
gr={1->2,1->3,1->6,1->7,2->4,3->4,4->5,5->6,5->7};
vcr={1-> {2,0},2-> {1,1},3-> {1,-1},4-> {0,0},5-> {4,0},6-> {3,1},7-> {3,-1}};
GraphPlot[gr,VertexLabeling-> True,
DirectedEdges-> False,
VertexCoordinateRules-> vcr,
ImageSize-> 250]
Method 2 (workaround)
erf= (If[MemberQ[{{5,4}},#2],
{ },
{Blue,Line[#1]}
]&);
gp[1] =
GraphPlot[
Join[{5->4},gr],
VertexLabeling->True,
DirectedEdges->False,
VertexCoordinateRules->vcr,
EdgeRenderingFunction->erf,
MultiedgeStyle->.8,
ImageSize->250
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个启动
下面检测是否有一条边“接触”不是其端点之一的顶点。
目前它仅适用于直线边缘。
该计划将其作为第一步,然后创建一个模拟边缘,如问题中发布的方法 2 所示。
使用我在此处发布的另一个答案。
Just a kickstart
The following detects if there is an edge that "touches" a vertex that is not one of its endpoints.
It works only for straight line edges right now.
The plan is using it as a first step and then creating a mock edge as in the method 2 posted in the question.
Uses another answer I posted here.
这是一个更尴尬的解决方法:
当然,我所做的是采用
FullForm 图形的图形并对其进行编辑。我向
GraphicsComplex
添加了几个点(即{0., 2.}
和{4., 2.}
),将在线中添加一些新的腿(即{6, 8}, {8, 9}, {9, 7}
)并删除在顶点 4 和 5 之间绘制线的腿。我不'并没有真正提供这个作为“解决方案”,但是比我有更多时间从事这方面工作的人应该能够编写一个函数来将 GraphicsComplex 操作为所需的形式。
Here's an even more awkward workaround:
Of course, what I've done is taken the
FullForm
of the graphic of the graph and edited it. I added a couple of points to theGraphicsComplex
(ie{0., 2.}
and{4., 2.}
), put some new legs into the line (ie{6, 8}, {8, 9}, {9, 7}
) and deleted the leg which drew the line between vertices 4 and 5.I don't really offer this as a 'solution' but someone with more time than I have to work on this should be able to write a function to manipulate the GraphicsComplex into a desired form.