Positioning new nodes in a graph

10 views (last 30 days)
I've the following graph
s = [1 1 1 2 2];
t = [2 3 4 2 5];
G = graph(s,t);
% plot
h = plot(G);
h.XData
h.YData
New nodes are added below
% add new nodes
G = addedge(G,[3 5],[6 7])
However, I want to position the new edges vertically (90 degree) above the existing nodes and not at the default positions.
For instance, the position of node 3 and 5 are [0.5492 0.9698] and [-0.8913 -0.9239] respectively.
I wish to retain the same x-coordinates for the new nodes 6 and 7 and add an offset to y-coordinate. e.g. offset = 0.05
The coordinates of 6 and 7 will be [0.5492 0.9698+offset] and [-0.8913 -0.9239+offset] .
Any suggestions on how this(or alternate ways) can be implemented will be really helpful.

Accepted Answer

Ganesh Regoti
Ganesh Regoti on 4 Feb 2020
Hi,
As per my understanding, you want to customize node positions on plot. Here is the link you can refer to
Here is sample code
s = [1 1 1 2 2];
t = [2 3 4 2 5];
G = graph(s,t);
% plot
h = plot(G);
h.XData
h.YData
x = h.XData;
y = h.YData;
G = addedge(G,[3 5],[6 7])
x = [x , x(3), x(5)];
y = [y, y(3)+0.5, y(5)+0.5]
plot(G,'XData',x,'YData',y);
Hope this helps!

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!