필터 지우기
필터 지우기

Positioning new nodes in a graph

조회 수: 7 (최근 30일)
Deepa Maheshvare
Deepa Maheshvare 2020년 1월 30일
답변: Ganesh Regoti 2020년 2월 4일
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.

채택된 답변

Ganesh Regoti
Ganesh Regoti 2020년 2월 4일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by