how to plot graph without intersection?

12 ビュー (過去 30 日間)
NA
NA 2018 年 12 月 13 日
編集済み: Christine Tobler 2018 年 12 月 18 日
I have this graph
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13;7 8;7 9;9 10;9 14;10 11;12 13;13 14]
when I use graph code,
G=graph(E(:,1),E(:,2))
h=plot(G)
plots graph with intersection.
Is there any codes that plot graph without intersection?
  2 件のコメント
KSSV
KSSV 2018 年 12 月 13 日
The intrsection depends on E. YOu have to provide E so that the points don't intersect.
NA
NA 2018 年 12 月 13 日
How can I do that?

サインインしてコメントする。

回答 (2 件)

Guillaume
Guillaume 2018 年 12 月 13 日
First, why is it a problem that some of the edges intersect in the plot? The plot is not ambiguous in any way, even if there are intersection between edges, the nodes are clearly marked. With a sufficiently complex graph, it's not going to be possible to plot it with some edges intersecting.
You can always experiment with the various Layout options of plot. e.g.
h = plot(G, 'Layout', 'circle')
although I've not found any default layout that doesn't have intersecting edges with your graph.
If you can work out yourself a node arrangement that doesn't lead to intersecting edges, you can always specify the position of the nodes when you call plot. Alternatively, you can let plot do its thing and manually move some nodes afterward:
h = plot(G)
h.XData([10 11]) = h.XData([7 8])
The above results in no intersection but as I've said with a sufficiently complex graph it may be impossible to plot it without intersections
  4 件のコメント
NA
NA 2018 年 12 月 13 日
it is work for my graph, but how can do you find [10 11] and [7 8]?
it means that of I have a other graph, how I can write this?
Guillaume
Guillaume 2018 年 12 月 13 日
There is no function built into matlab that can do it automatically for any arbitrary graph. plot does its best, but it's not its priority to avoid intersection because for most people they don't matter (and I still don't understand why they matter to you).
You will either have to write your own plotting function (or at the very least work out an algorithm that find the optimal position of the nodes for your use case), something that is not trivial at all (probably a PhD worth) or do it manually by looking at the graph and manually moving nodes until there's no intersection.
In this particular case, I just looked at the graph and noticed that if I positioned node 10 at the same X position as node 7 and node 11 at the same X position as node 8, there was no intersection.

サインインしてコメントする。


Christine Tobler
Christine Tobler 2018 年 12 月 13 日
It sounds like you are looking for functionality related to planar graphs. MATLAB does not have any methods specific to this, but the MATLAB BGL on the File Exchange provides some functionality (checking if a graph is planar, and computing a straight-line drawing in that case).
I'd be interested to learn some more about your application. Are you looking to extract all the faces of the straight-line drawing of your graph? And what is the next step to do with these faces?
  8 件のコメント
Guillaume
Guillaume 2018 年 12 月 18 日
You have to explain why some loops/faces are included in your graph, and not others. E.g. why isn't [5, 6, 13, 14, 9, 4] in your S?
Christine Tobler
Christine Tobler 2018 年 12 月 18 日
編集済み: Christine Tobler 2018 年 12 月 18 日
I agree with Guillaume: To give a general method of finding s, we need a general and unique description of what s needs to be (which will then also tell us what makes s different from M).
Do you want faces that are all triangles? (But M has some faces that are not triangles). From your example, I don't know what the general criterion is.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by