# Positioning new nodes in a graph

22 views (last 30 days)
Deepa Maheshvare on 30 Jan 2020
Answered: Ganesh Regoti on 4 Feb 2020
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
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.

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;
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!

### Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!