Borrar filtros
Borrar filtros

Hi.how i can draw a graph like this? that have pyramid shape.the links between nodes have different thickness and darkness.

1 visualización (últimos 30 días)
  2 comentarios
John D'Errico
John D'Errico el 16 de Feb. de 2018
Editada: John D'Errico el 16 de Feb. de 2018
What have you tried? If nothing, then why not? Have you tried using line? plot or even patch? You need to learn to use the graphics tools, things that allow you to specify and change aspects of a plotted line.
I would suggest however, line thickness is not a good thing to vary here, since that thickness is not easy to discern. A far better choice would be to use a fixed thickness, but use color variations to distinguish the different edges. Color is far easier to see a subtle difference, something you would never recognize from only a subtle change in thickness, if at all.
ali jafari
ali jafari el 16 de Feb. de 2018
thanks. i wrote this code. and plot this figure but the some nodes are useless. the thickness show the degree of similarity between the nodes. your suggest is very good. pleas suggest a code to me.thank u.
if true
s = [11 11 21 22 22 31 32 33 31 41 41 42 43 44 51 52 53 53 54 55];
t = [21 22 31 32 33 41 42 43 44 51 55 52 53 54 61 62 63 66 64 65];
weights = [50 10 20 80 90 60 40 50 20 10 11 12 13 14 15 16 17 18 19 20];
G = graph(s,t,weights);
plot(G)
end
{
}

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 16 de Feb. de 2018
When you use numeric vectors as your source and target inputs, MATLAB assumes you want one node for each integer value from 1 to the maximum value stored in either s or t, whichever is greater. So since t has a maximum value of 65, your graph will have 65 nodes.
Since I suspect the values in s and t are meant to be identifiers, not node numbers (you wouldn't add 1 to an element of s and necessarily expect it to mean something, right?) I would convert them into text data.
s = [11 11 21 22 22 31 32 33 31 41 41 42 43 44 51 52 53 53 54 55];
t = [21 22 31 32 33 41 42 43 44 51 55 52 53 54 61 62 63 66 64 65];
weights = [50 10 20 80 90 60 40 50 20 10 11 12 13 14 15 16 17 18 19 20];
sc = arrayfun(@num2str, s, 'UniformOutput', false);
tc = arrayfun(@num2str, t, 'UniformOutput', false);
G = graph(sc, tc, weights);
h = plot(G, 'layout', 'layered')
This doesn't look exactly like the picture you showed, but it's closer. If you want finer-grained control over exactly where the nodes appear, change the XData and YData properties of the GraphPlot object h or call plot with the 'XData' and 'YData' parameters. For instance, to stretch the Y axes a bit and give extra spacing between the levels:
figure
h2 = plot(G, 'XData', 2*h.XData, 'YData', h.YData.^2)
You can even tweak one or two points, if the 'layered' layout gets you close to what you want.
% Find nodes '42', '43', and '44'
n = findnode(G, {'42', '43', '44'});
% Move '42' into the position previously occupied by '43'
% Move '43' into the position previously occupied by '44'
% Move '44' into the position previously occupied by '42'
h.XData(n) = h.XData(n([2 3 1]));
Now, if you still want to represent some quality of the edges using thickness, use the highlight function on the GraphPlot object (not the graph or digraph itself.)
highlight(h, '11', 'NodeColor', 'r')
highlight(h, '11', '21', 'EdgeColor', 'k')

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by