How to plot 4 nodes in a weighted digraph as a square?

1 view (last 30 days)
I am trying to control the layout of a digraph consisting of two pairs of nodes so the graph looks something like this:
node1_pair1 <-> node1_pair2
node2_pair1 <-> node2_pair2
I would like the two pairs to be arranged in a square, with either pair showing weighted connections to the other. When there are only "horizontal connections" (e.g. node1_pair1 -> node1_pair2), I am able to retain a square arrangement of nodes by using the layout function:
layout(p,'layered','direction','right');'
However, when I try to add a "diagonal" connection (e.g. node1_pair1 -> node2_pair2) or vertical connection, the nodes lose their square arrangemnt. How can I retain a square arrangement of nodes regardless of the connections I add?

Accepted Answer

Steven Lord
Steven Lord on 29 May 2019
None of the provided layout functions allow you to fix the relative positions of a set of four nodes like this.
You could use layout to arrange the nodes iniitally then modify the XData and YData properties for those specific nodes to force them into a square, or skip layout entirely and set the XData and YData properties initially if these are the only nodes in your digraph or if the nodes have coordinates independent of the structure of the digraph. This post on Loren's blog uses the latter technique in the "Visualizing the results" section to plot nodes representing state capitals in the centroid of their states (which are mostly independent of the connections of the state capitals) and the result looks like a map of the United States (if you use a bit of imagination.)

More Answers (0)

Categories

Find more on Networks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!