Positioning new nodes in a graph

10 visualizaciones (últimos 30 días)
Deepa Maheshvare
Deepa Maheshvare el 30 de En. de 2020
Respondida: Ganesh Regoti el 4 de Feb. de 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
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.

Respuesta aceptada

Ganesh Regoti
Ganesh Regoti el 4 de Feb. de 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!

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by