Plot a planar graph as a planar graph?
2 次查看(过去 30 天)
显示 更早的评论
I've got an application dealing with planar graphs where the fact that they're planar is important, and so my representations of those graphs should emphasise this. However, when I use plot() to plot them, it often creates unnecessary overlapping edges. None of the 'Layout' options correspond to planarity, and none of them seem to prevent the problem in all cases.
Is there a way, given an arbitrary planar graph, to have Matlab plot it while respecting that planarity? I do not want to generate points to place the nodes; I would like Matlab to do that automatically.
0 个评论
回答(1 个)
Leepakshi
2025-3-6
Hi Richard,
plot function for graphs doesn't specifically ensure a planar layout. However, you can use the layout function with the force or layered option as a starting point, though they may not guarantee planarity. But we can draw it in a manner that it follows the planar rules best.
Post ensuring your graph is planar using algorithms like Kuratowski's theorem or using third-party tools, force layout can be useful to achieve the desired format. The force layout is a force-directed algorithm that simulates a physical system where nodes repel each other like charged particles, and edges act like springs holding the nodes together. Force-directed layouts are particularly useful for visualizing the overall structure of a graph, as they tend to highlight clusters and reveal underlying patterns.
% Example graph
s = [1 1 1 2 2 3 3 4];
t = [2 3 4 3 5 4 5 5];
G = graph(s, t);
% Attempt to plot with a force-directed layout
h = plot(G, 'Layout', 'force');
Please review the following documentation on layout and determine if any other layout might be more beneficial.
Hope this helps!
1 个评论
Andrew Sol
2025-7-6
As you said, it doesn't work on all graphs, but in Mathematica there is such a tool! At the same time, in Matlab there are some tools that Mathematica doesn't have!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!